A. Jabber ID
来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/06/05 16:41
A. Jabber ID
time limit per test
0.5 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputJabber 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.
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
- A. Jabber ID
- codeforces 21A Jabber ID
- CodeForces 21A Jabber ID (简单题)
- 【模拟+读入】#21 A. Jabber ID
- Jabber ID(codeforce)
- Jabber
- jabber
- Jabber
- jabber
- jabber
- Jabber
- Building a Jabber Client for iOS: Server Setup
- Building a Jabber Client for iOS: Interface Setup
- Building a Jabber Client for iOS: XMPP Setup
- Building a Jabber Client for iOS: Server Setup
- Building a Jabber Client for iOS: Interface Setup
- Building a Jabber Client for iOS: XMPP Setup
- Building a Jabber Client for iOS: Server Setup
- A. Flag
- A. Noldbach problem
- A. Triangle
- A. World Football Cup
- A. BerOS file system
- A. Jabber ID
- A. Second Order Statistics
- A. You\'re Given a String...
- A. Ring road
- A. IQ test
- A. Almost Prime
- A. Next Test
- Oracle内置表二
- A. Spit Problem