7-1 统计大写辅音字母 (15分)
英文辅音字母是除A、E、I、O、U以外的字母。本题要求编写程序,统计给定字符串中大写辅音字母的个数。
输入格式:
输入在一行中给出一个不超过80个字符、并以回车结束的字符串。
输出格式:
输出在一行中给出字符串中大写辅音字母的个数。
输入样例:
HELLO World!
输出样例:
4
作者
C课程组
单位
浙江大学
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include<stdio.h>
int main(void)
{
char s[80];
int count=0,i=0,*ret;
ret=s;
//错误代码:s是一个地址常量 s++不合法
/* while((*s=getchar())!='\n')
s++;
*s='\0';
s=ret; */
while((s[i]=getchar())!='\n'){
i++;
}
s[i]='\0';
/* ret=s;
while(*ret!='\0'){
if(*ret>='B'&&*ret<='Z'&&*ret!='E'&&*ret!='I'&&*ret!='O'&&*ret!='U')
count++;
ret++;
}*/
for(i=0;s[i]!='\0';i++){
if(s[i]>='B'&&s[i]<='Z'&&s[i]!='E'&&s[i]!='I'&&s[i]!='O'&&s[i]!='U')
count++;
}
printf("%d",count);
return 0;
}