hdu 1039 (string process, fgets, scanf, neat utilization of switch clause) 分类: hdoj 2015-06-16 22:15 38人阅读 评论(0) 收藏

(string process, fgets, scanf, neat utilization of switch clause)

simple problem, simple code.

#include <cstdio>
#include <algorithm> #define MAXLEN 22
char password[MAXLEN]; int main() {
//freopen("input.txt","r",stdin);
int nc,nv,vcnt, invalid;
char *p;
while(scanf("%20s",password)==1 && strcmp(password,"end")!=0) {
nc=nv=vcnt=0; invalid=0;
p=password-1;
while(*++p) {
switch(*p) {
case 'e':
case 'o':
case 'a':
case 'i':
case 'u':
++vcnt; ++nv; nc=0; break;
default:
++nc; nv=0; break;
}
if(*p==*(p+1) && *p!='e' && *p!='o') { invalid=1; break; }
if(nc>2 || nv>2) { invalid=1; break; }
}
if(invalid || vcnt==0) printf("<%s> is not acceptable.\n",password);
else printf("<%s> is acceptable.\n",password);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。// p.s. If in any way improment can be achieved, better performance or whatever, it will be well-appreciated to let me know, thanks in advance.

上一篇:读书笔记 effective c++ Item 31 把文件之间的编译依赖降到最低


下一篇:HDU 5876 关于补图的bfs