(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.