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 ...
随机推荐
- 【Android】15.2 广播
分类:C#.Android.VS2015: 创建日期:2016-02-29 一.简介 Android系统和你自己编写的应用程序都可以通过Indent发送和接收广播信息.广播的内容既可以是自定义的信息, ...
- svn add xxx.txt 提示A (bin) xxx.txt
[root@NGINX-APACHE-SVN iptables]# svn ci -m "add iptables.txt" Adding (bin) iptables/iptab ...
- 【转】在MAC下配置MySQL 5.7 数据库的编码问题
1.MySQL 5.7 for MAC 默认没有my.cnf文件 ,首先 新建my.cnf文件: 2.在my.cnf文件追加 1 2 3 4 5 6 7 8 [mysqld] character-se ...
- 【已解决】vbox + ubuntu 设置 1366x768 分辨率
1. 打开VBOX(Oracle VM VirtualBox),启动Ubuntu 2. 点击"设备>安装增强功能" 3. 进入Ubuntu打开文件管理器,如下图 4. 输入r ...
- IIS短文件名泄露漏洞危害及防范方法(转)
攻击方法(转自http://blog.sina.com.cn/s/blog_64a3795a01017xqt.html) 一直在寻找一种方法,如果我可以使用通配符"*" 和 &qu ...
- Linux samba 服务的配置
今天有个学生问我 samba 服务怎么配置,所以晚上特意研究一下怎么配置这个服务. 过程如下: sudo apt-get install samba samba-common // 安装 samba ...
- Mysql研磨之设计索引原则
1.搜索的索引列:最适合索引的列是出现在where子句中的列,或链接子句中指定的列,而不是出现在select关键词后的选择列表中的列 2.使用唯一索引:考虑列中值的分布.索引的列基础越大,索引的效果越 ...
- keepalive的作用
keepalive的作用是实现高可用,通过VIP虚拟IP的漂移实现高可用.在相同集群内发送组播包,master主通过VRRP协议发送组播包,告诉从主的状态. 一旦主挂了从就选举新的主,实现高可用 LV ...
- Javascript代码执行过程-《悟透Javascript》笔记
本文摘录自李战老师<悟透Javascript>一书的部分章节,为适应博客发表作了一点点修改. 1) 预编译分析. JavaScript执行引擎将所有定义式函数直接创建为作用域上的函数变量, ...
- web页面防盗链功能使用--request.getHeader("Referer")
使用Request对象设置页面的防盗链 所谓的防盗链就是当你以一个非正常渠道去访问某一个Web资源的时候,服务器会将你的请求忽略并且将你的当前请求变为按正常渠道访问时的请求并返回到相应的页面,用户只有 ...