输入一串字符,分别输出字母 数字 符号的个数,以$结束

来源:互联网 发布:中国象棋人机对战软件 编辑:程序博客网 时间:2024/05/16 19:50
# include <iostream>using namespace std;int main(){char ch;int xiao = 0;int da = 0;int num = 0;int space = 0;int qi = 0;cout << "请输入一串字符,以$结束:\n";while((ch = getchar()) != '$'){if(ch >= 'a' && ch <= 'z'){++xiao;}else if(ch >= 'A' && ch <= 'Z'){++da;}else if(ch >= 48 && ch <= 57){++num;}else if(ch == ' '){++space;}else{++qi;}}cout << "小写字母:" << xiao << endl << "大写字母:" << da << endl << "数字:" << num << endl << "空格:" << space << endl << "其他字符:" << qi << endl;return 0;}

原创粉丝点击