[UVA494]Kindergarten Counting Game
#include<cstdio>
#include<cstring>
#include<cctype>
#define maxn 1000
int main(void)
{
char s[maxn];
memset(s,' ',sizeof(s));
while(gets(s))
{
int len = strlen(s), count = 0, a = 0;//a = 0 目前為字母 1為其他非字母
for(int i=0;i<len;i++)
{
if(isalpha(s[i]) && !a)
{
a = 1;
count++;
}
else if(!isalpha(s[i]) && a)
a = 0;
}
printf("%d\n",count);
}
return 0;
}
#include<cstring>
#include<cctype>
#define maxn 1000
int main(void)
{
char s[maxn];
memset(s,' ',sizeof(s));
while(gets(s))
{
int len = strlen(s), count = 0, a = 0;//a = 0 目前為字母 1為其他非字母
for(int i=0;i<len;i++)
{
if(isalpha(s[i]) && !a)
{
a = 1;
count++;
}
else if(!isalpha(s[i]) && a)
a = 0;
}
printf("%d\n",count);
}
return 0;
}
留言
張貼留言