本文主要是介绍A. Jabber ID,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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.
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.
Print YES or NO.
mike@codeforces.com
YES
john.smith@codeforces.ru/contest.icpc/12
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;
}
这篇关于A. Jabber ID的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!