今日任务:
代码:
#include <iostream>
using namespace std;
int main()
{
/*
* 输入字符串统计大写、小写、数字、空格以及其他字符的个数
*
*/
string s;
cout << "请输入一个字符串" << endl;
//cin >> s;
getline(cin,s);
int small=0,big=0,number=0,space=0,other=0;
for(int i=0;i<(int)s.size();i++){
cout << s[i] <<endl;
if('a'<=s[i]&& s[i]<='z'){
small++;
}else if('A'<=s[i]&& s[i]<='Z'){
big++;
}else if(0<=s[i]&& s[i]<=9){
number++;
}else if(s[i]==' '){
space++;
}else{
other++;
}
}
cout << "small=" << small << " big=" << big << " number=" << number << "space" << space<< " other=" << other <<endl;
return 0;
}
运行结果:
今日思维导图