A. Jabber ID

来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/06/05 16:41
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.com007@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.

Sample test(s)
input
mike@codeforces.com
output
YES
input
john.smith@codeforces.ru/contest.icpc/12
output
NO
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
char s[205];

int dig(char c)
{
if(c>='0'&&c<='9')return 1;
return 0;
}
int let(char c)
{
if(c>='A'&&c<='Z' || c>='a'&&c<='z')return 1;
return 0;
}

int check()
{
int n = strlen(s), p = 0;
while(p<n && s[p]!='@')p++;
if(p==n) return 0;
if(p < 1 || p > 16)return 0;
//puts("==");

for(int i = 0; i < p; i++)
if(s[i]!='_' && !dig(s[i]) && !let(s[i]))return 0;
//puts("===");
int pre = p+1;
while(p<n && s[p]!='/')p++;
if(p-pre<1 || p-pre>32)return 0;

int cnt = 0;
for(int i = pre; i < p; i++)
{
if(s[i]=='.')
{
if(cnt<1 || cnt>16)return 0;
cnt
= 0;
}
else
{
if(s[i]!='_' && !dig(s[i]) && !let(s[i]))
return 0;
cnt
++;
}
}
if(cnt<1 || cnt>16)return 0;

if(p < n)
{
//puts("--");
cnt
= 0;
for(int i = p+1; i < n; i++)
{
if(s[i]=='/')
{
if(cnt<1 || cnt>16)return 0;
cnt
= 0;
}
else
{
if(s[i]!='_' && !dig(s[i]) && !let(s[i]))
return 0;
cnt
++;
}
}
if(cnt<1 || cnt>16)return 0;
}
return 1;
}
int main()
{
scanf
("%s",s);
puts
(check()?"YES":"NO");

return 0;
}

0 0
原创粉丝点击