7-23 统计字符 (15分) 本题要求编写程序,输入10个字符,统计其中英文字母、空格或回车、数字字符和其他字符的个数。

7-23 统计字符 (15分)
本题要求编写程序,输入10个字符,统计其中英文字母、空格或回车、数字字符和其他字符的个数。

输入格式:
输入为10个字符。最后一个回车表示输入结束,不算在内。

输出格式:
在一行内按照letter = 英文字母个数, blank = 空格或回车个数, digit = 数字字符个数, other = 其他字符个数
的格式输出。

输入样例:
aZ &
09 Az
输出样例:
letter = 4, blank = 3, digit = 2, other = 1

#include<iostream>
using namespace std;
int main(){
    
    
	char c;
	int i,digit=0,letter=0,blank=0,other=0;
	for(i=0;i<10;i++){
    
    
		c=getchar();
		if(c>='0'&&c<='9')
			digit++;
		else if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
			letter++;
		else if(c==' ' ||c=='\n')
			blank++;
		else 
			other++;
	}
	cout<<"letter = "<<letter<<", "<<"blank = "<<blank<<", "<<"digit = "<<digit<<", "<<"other = "<<other;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45534301/article/details/112475316