Code Forces 21 A(模拟)
0.5 second
256 megabytes
standard input
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.
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<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;
}
Code Forces 21 A(模拟)的更多相关文章
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- code forces 436 C. Bus
C. Bus time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...
- CODE[VS]-蛇形矩阵-模拟-天梯白银
题目描述 Description 小明玩一个数字游戏,取个n行n列数字矩阵(其中n为不超过100的奇数),数字的填补方法为:在矩阵中心从1开始以逆时针方向绕行,逐圈扩大,直到n行n列填满数字,请输出该 ...
- code forces 439 C. The Intriguing Obsession
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- EZ 2018 04 21 NOIP2018 模拟赛(十) -LoliconAutomaton的退役赛
难得的一次Unrated,避免了重回1500的尴尬 其实题目都还可以,但只不过所有人T1都炸了,可能是数据的锅(假的) 而且我因为T1SB的把T2弃了,没想到是千年水题 T3莫名爆炸,然后TM的40分 ...
- EZ 2018 04 21 NOIP2018 模拟赛(九)
终于停止了掉Rating的浪潮! 猥琐的链接 这次200分才Rank10,而且很多人并列 庆幸T2最后20分钟发现期望的算法打错了,然后拿到了50pts,250收场 T1 水题*1 这道题不仅做过,而 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
随机推荐
- Genymotion INSTALL_FAILED_CPU_ABI_INCOMPATIBLE
出现这个错误的原因是Genymotion默认的处理器是x86的,不是arm的.所以安装的时候会出错,仅仅要把x86转换成arm就能够了. 转换方法: 1.下载转换的zip文件:X86 to ARM 2 ...
- 关于Unity层级面板的自动初始化
Transform[],GameObject[]这些class类型,Unity会进行自动初始化. 但[ExecuteInEditMode]在编辑模式下执行的时候,会发现初始化其实也是有顺序的,并且在U ...
- CA证书的信认
为什么不同的品牌证书,价钱不一样: 衡量证书一般是看通用型,就是大家认不认你,或者说,你买的证书的根证书有没有被设备内置,内置了,你就是可信的, 没内置,就没法用.
- 如何使用微信JS-SDK实际分享功能
http://jingyan.baidu.com/album/d3b74d64c517051f77e609ed.html?picindex=7
- 0071 CentOS_Tomcat访问文件名包含中文的文件出现404错误
访问CentOS+Tomcat下的,文件名包含中文的文件出现404错误 修改:apache-tomcat-7.0.78/conf/server.xml <Connector port=" ...
- androidStudio简便安装
最近在公司由eclipse换为androidstudio,说句实话,androidstudio还是蛮好用的,但是自己刚刚安装的时候遇到很多的问题,问了度娘,各种说法都有,还是捣鼓不得,于是自己尝试,弄 ...
- Linux解决删除文件后空间没有释放问题_端口占用问题
使用命令 (1) losf | grep deleted 查询所有已经删除但是还未释放空间的进程,找到容量最大的线程,kill -9 pid 然后等待容量释放 (2) netstat -ano | g ...
- php之道
PHP The Right Way. Tweet 欢迎 目前网络上充斥着大量的过时资讯,让 PHP 新手误入歧途,并且传播着错误的实践以及不安全的代码.PHP 之道 收集了现有的 PHP 最佳实践.编 ...
- 关于Unity的C#基础学习(四)
一.数组 存放同种类型的一组数据,同类+多个 1.定义 int [] int_set; int_set=new int[10]; //在堆上分配出10个int,int_set是数组的引用变量,指向1 ...
- MySQL的innodb_flush_log_at_trx_commit配置值的设定
MySQL的innodb_flush_log_at_trx_commit配置值的设定 mysql的配置文件中innodb_flush_log_at_trx_commit的默认值是1,修改成0或者2,速 ...