题意:无聊的字符串模拟。每个字符只输出第一次出现,并且过滤掉元音。
思路:模拟。注意标点之前不能有空格(代码中space变量的作用,而不是每个单词后直接输出空格)
#include <stdio.h>
#include <string.h>
#define N 75
char s[N];
int used[30];
int isvowel(char x){
return x=='A'||x=='E'||x=='I'||x=='O'||x=='U';
}
int main(){
int i,flag,space=0;
gets(s);
for(i = 0;s[i]!='\0';i++){
flag = 0;
while(s[i]!=' '&&s[i]!='\0'){
if(s[i]>='A'&&s[i]<='Z'&&(isvowel(s[i]) || used[s[i]-'A'])){
i++;
continue;
}
if(s[i]>='A'&&s[i]<='Z'&&!used[s[i]-'A']){
used[s[i]-'A'] = 1;
if(space){
putchar(' ');
space = 0;
}
}
putchar(s[i]);
flag = 1;
i++;
}
if(s[i]==' ' && flag)
space = 1;
if(s[i] == '\0')
break;
}
}
该博客介绍了POJ 1951题目的解决方案,涉及字符串模拟的过程,其中强调每个字符仅输出首次出现,并且在处理过程中排除了元音字母。文章还提及在输出时需要注意标点符号前不应有空格的细节。
1436

被折叠的 条评论
为什么被折叠?



