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 ...
随机推荐
- Linux下UTF-8和GB2312互相转换的函数
#include<iconv.h> #include <stdio.h> #include<iconv.h>using namespace std; int utf ...
- CWidgetMgr---H
/************************************************************************/ //管理部件 //部件自动根据Z顺序调整消息的优先 ...
- 批处理-IF详解
在CMD使用IF /?打开IF的系统帮助(自己看我就不全部列出来了),我们会发现IF有3种基本的用法! IF [NOT] ERRORLEVEL number command IF [NOT] stri ...
- jsp学习之scriptlet的使用方法
scriptlet的使用 jsp页面中分三种scriptlet: 第一种:<% %> 可以在里面写java的代码.定义java变量以及书写java语句. 第二种:<%! %> ...
- 禁止Chrome浏览器自动升级
对于我们测试人员来说,浏览器自动升级是非常可怕的,浏览器的升级会导致出现各种bug,比如我们常用的Selenium,如果Chrome浏览器自动升级就会导致脚本出错,无法打开浏览器等等情况,对于这种情况 ...
- arrow:让Python的日期与时间变的更好
在处理数据的时候经常会碰见各种时间数据,但因为时间数据的格式不统一,所以导致数据处理的时候有一些麻烦.Python的标准库提供了相应模块,但可用性却不高,也不够人性化.本专栏之前已经有文章介绍过在R中 ...
- js监听 window.open 关闭事件
转载自:http://blog.csdn.net/hanshileiai/article/details/41346729 首先创建一个新的对象,这将打开一个弹出这样的: var winObj = w ...
- php读取csv的问题
csv文件要用utf-8 无bom格式保存 如果有英文外的字符,另外每项要用双引号,不用双引号不能保存非英文字符
- js 開始时间,当前时间,结束时间的比較
//開始时间不能小于当前时间 function startTimeIsBigThanTotay(startTime){ var startdate = new Date((startTime).rep ...
- 科技巨头们以 "A" 取名的时尚潮流
科技巨头们以 "A" 取名的时尚潮流 from 公众号 WebHub 世界上有许多巨头公司喜欢以字母 a 打头作公司起名.改名,这主要是因为电话薄是以字母排序的(外国人习惯家里 ...