【模拟+读入】#21 A. Jabber ID
来源:互联网 发布:回龙观矩阵托管 编辑:程序博客网 时间:2024/06/05 15:41
这道题是一个给你一个邮箱地址看看合不合规矩的判定:
1.由“A@B/C”的形式组成,A在16个字符内,B在32个字符(不包括.)内,C在16个字符内;
2.可以没有“/C”,但是@的前后都至少要有一个字符
3.B可以由好多个'.'分开,但是每个单词不能超过16个字符。
4.允许的字符在'_' isupper() isdigit() islower() 范围内
我傻乎乎的还想用
scanf("%s@%s/%s",a,b,c);这样的格式来偷懒……看来是正则表达式看的异想天开了。
AC-Code:
#include <cstdio> #include <string>#include <cstring> #include <iostream> //http://blog.csdn.net/okcd00/article/details/27669883using namespace std; #define Giveup {cout<<"NO"<<endl;return 0;}char str[101]; bool judge(char c){ return (c=='_'||islower(c)||isdigit(c)||isupper(c)); }int main() { //freopen("in.txt","r",stdin); int cnt=0; int count=0;//each words - Whole hostname int type=0;//0-username 1-hostname 2-resource while(scanf("%s",str)!=EOF) {type=0;//init is username input int len=strlen(str); for(int i=0;i<len;i++) { char c=str[i]; //change kind if(c=='@') { if(type==1) Giveup type=1; //change to hostname if(cnt<1||cnt>16) Giveup; cnt=0; } else if(c=='/') { if(type==2) Giveup type=2;//change to resource if(cnt<1||cnt>16) Giveup if(count<1||count>32) Giveup cnt=0; } else if(c=='.') { if(type!=1) Giveup if(cnt<1||cnt>16) Giveup cnt=0; } else if(c>127||c<33) Giveup else if(type==0) { if(judge(c)) { cnt++; continue; } else Giveup } else if(type==1) { if(judge(c)) { cnt++; count++; continue; } else Giveup } else if(type==2) { if(judge(c)) { cnt++; continue; } else Giveup } } if(cnt<0||cnt>16) Giveup if(type>=1&&cnt>0) cout<<"YES"<<endl; else Giveup }}
调试用代码:
#include<map>#include<string>#include<cstdio>#include<ctype.h>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define Nx cout<<"NO"char str[101];int main(){//freopen("in.txt","r",stdin);int cnt=0;int count=0;//each words - Whole hostnameint type=0;//0-username 1-hostname 2-resourcetype=0;//init is username inputwhile(scanf("%s",str)!=EOF);int len=strlen(str);for(int i=0;i<len;i++){char c=str[i];//change kindif(c=='@'){if(type==1){Nx;//printf("NO in @");return 0;} type=1;//change to hostnameif(cnt<1||cnt>16){Nx;//printf("NO in @");return 0;} cnt=0;}else if(c=='/'){if(type==2){Nx;//printf("NO in @");return 0;} type=2;//change to resourceif(cnt<1||cnt>16){Nx;//printf("NO in host small");return 0;} if(count<1||count>32){Nx;//printf("NO in host big");return 0;} cnt=0;}else if(c=='.'){if(type!=1) {Nx;//printf("NO in .");return 0;} if(cnt<1||cnt>16){Nx;//printf("NO in .");return 0;} cnt=0;}else if(c>127||c<33)//test if ASCII is right{//if(scanf("%c",&c)!=EOF) test failed{Nx;//printf("\nNO in range: %c",c);return 0;}}else if(type==0){if(isupper(c)||islower(c)||isdigit(c)||c=='_') {cnt++;continue;}else Nx;//printf("NO in c wrong 0");return 0;}else if(type==1){if(isupper(c)||islower(c)||isdigit(c)||c=='_') {cnt++;count++;continue;}else Nx;//printf("NO in c wrong 1");return 0;}else if(type==2){if(isupper(c)||islower(c)||isdigit(c)||c=='_'){cnt++;continue;} else Nx;//printf("NO in c wrong 2");return 0;}}if(cnt<0||cnt>16){Nx;//printf("NO in resource");return 0;}if(type>=1&&cnt>0) printf("YES");else Nx;return 0;}
0 0
- 【模拟+读入】#21 A. Jabber ID
- codeforces 21A Jabber ID
- CodeForces 21A Jabber ID (简单题)
- A. Jabber ID
- Jabber ID(codeforce)
- Jabber
- jabber
- Jabber
- jabber
- jabber
- Jabber
- Building a Jabber Client for iOS: Server Setup
- Building a Jabber Client for iOS: Interface Setup
- Building a Jabber Client for iOS: XMPP Setup
- Building a Jabber Client for iOS: Server Setup
- Building a Jabber Client for iOS: Interface Setup
- Building a Jabber Client for iOS: XMPP Setup
- Building a Jabber Client for iOS: Server Setup
- 队列的应用
- Windows网络系统架构
- Win7下解决修改注册表 返回ERROR_ACCESS_DENIED 的错误--解决办法 MFC
- 白话windows内核对象共享之复制对象句柄
- IE8、9、10下图片旋转
- 【模拟+读入】#21 A. Jabber ID
- python命令行方式操作数据库
- 连载《一个程序员的成长历程》-6.自学C++,机遇的开始
- ORA-12560: TNS: 协议适配器错误
- 迟钝的五官
- HDOJ 1248 寒冰王座
- Android开源项目 分类 便于查看
- html单线表格
- Java面向对象 线程技术--上篇