Code Forces 21 A(模拟)
2016-04-16 11:06
344 查看
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
output
input
output
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; }
相关文章推荐
- NSRunLoop详解
- Code Forces 21 A(模拟)
- JVM学习笔记三:JVM类加载机制
- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:31:compile (default-co
- 4--网关
- 3--TCP三次握手
- NYOJ-106背包问题
- 获取天气预报API
- 2011上交:整除问题
- Mysql 二进制免编译安装
- shader内置函数
- NKOI 2152 滑动窗口
- Apache 源码包安装
- 深度优先搜索
- 求数组中最长递增子序列
- 【UNET自学日志】Part2 旋转同步
- hdu 1171 Big Event in HDU(0-1背包问题)
- 使用cookie实现记录浏览商品的过程并能够清空浏览记录(简单的小程序不涉及到数据库的调取)
- 协议(protocol)
- MYSQL之数据类型