Code Forces 21 A(模拟)

A. Jabber ID

time limit per test

0.5 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where

  • <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of<username> is between 1 and 16, inclusive.
  • <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.
  • <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of<resource> is between 1 and 16, inclusive.

The content of square brackets is optional — it can be present or can be absent.

There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.

Your task is to write program which checks if given string is a correct Jabber ID.

Input

The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.

Output

Print YES or NO.

Examples

input

mike@codeforces.com

output

YES

input

john.smith@codeforces.ru/contest.icpc/12

output

NO
直接模拟
#include<stdio.h>
#include<string.h>
bool panduan(char c)
{
	if((c!='_')&&(c<'a'||c>'z')&&(c<'A'||c>'Z')&&(c<'0'||c>'9'))return false;
	else return true;
}
int main()
{
	char s[100+10];
	gets(s);



	int len=strlen(s);
	char user[100];
	char host[100];
	char res[100];
	int i,len1,len2,len3;
	int ans=1;
	//user
	for(i=0;i<len;i++)
	{
		if(s[i]=='@')
		{
			len1=i;
			break;
		}
		user[i]=s[i];
		if(i==len-1&&s[i]!='@')ans=0;
	}
	if(s[len-1]=='@')
        ans=0;
	if(ans==1)
	{
		if(len1<1||len1>16)ans=0;
		else
		{
			for(i=0;i<len1;i++)
			{
				if(!panduan(user[i]))
				{
					ans=0;
					break;
				}
			}
		}
	}
	//host
	for(i=len1+1;i<len;i++)
	{
		if(s[i]=='/')
		{
			len2=i-len1-1;
			break;
		}
		host[i-len1-1]=s[i];
		if(i==len-1&&s[i]!='/')
		{
			len2=len-len1-1;
		}
	}
	if(ans==1)
	{
		if(len1<1||len1>32)ans=0;
		else
		{
			int sum=0;
			for(i=0;i<len2;i++)
			{
				if(!panduan(host[i]))
				{
					if(host[i]=='.')
                    {
                        if(sum>16||sum<1||(i==len2-1))
				        {
					       ans=0;break;
				        }
                        sum=0;
                    }
					else ans=0;
				}
				else sum++;
				if(ans==0)
                    break;

			}
		}
	}
	//res
	if(s[len-1]=='/')
        ans=0;
	if(len1+len2+2<len&&ans==1)
	{
		for(i=len1+len2+2;i<len;i++)
		res[i-len1-len2-2]=s[i];
		len3=len-2-len1-len2;
		if(len3<1||len3>16)ans=0;
		else{
		for(i=0;i<len3;i++)
		{
			if(!panduan(res[i]))
			{
				ans=0;
				break;
			}
		}}
	}

	if(ans==1)printf("YES\n");
	else printf("NO\n");

	return 0;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Hongten

HIbernate 中的 继承映射

数据库中Delivery表:id,recipient,phone,address,postcode,delivery_type,parcel_number,ex...

7410
来自专栏ml

HDUOJ-------2719The Seven Percent Solution

The Seven Percent Solution Time Limit: 2000/1000 MS (Java/Others)    Memory Limi...

30650
来自专栏数据结构与算法

BZOJ4300: 绝世好题(dp)

给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len)。

10830
来自专栏ml

HDUOJ-----1066Last non-zero Digit in N!

Last non-zero Digit in N! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit...

34360
来自专栏算法修养

CodeForces 639 A

Bear and Displayed Friends time limit per test2 seconds memory limit per tes...

28040
来自专栏码匠的流水账

聊聊spring cloud gateway的streaming-media-types属性

本文主要研究下spring cloud gateway的streaming-media-types属性

28110
来自专栏小樱的经验随笔

HDU 5882 Balanced Game

Balanced Game Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/3276...

35890
来自专栏函数式编程语言及工具

Scalaz(40)- Free :versioned up,再回顾

   在上一篇讨论里我在设计示范例子时遇到了一些麻烦。由于Free Monad可能是一种主流的FP编程规范,所以在进入实质编程之前必须把所有东西都搞清楚。前面遇...

237100
来自专栏码匠的流水账

reactor-netty的TcpClient如何往eventLoop提交task

本文主要研究一下reactor-netty的TcpClient如何往eventLoop提交task

51520
来自专栏ml

hdu 1829 A Bug's Life(分组并查集(偏移量))

A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/3276...

37780

扫码关注云+社区

领取腾讯云代金券