注意可以输入空格,算其它字符
2026-05-24 16:47:45
发布于:湖北
2阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
int a1=0,a2=0,a3=0;
getline(cin,a); //可以输入空格
for(int i=0;i<a.size()-1;i++){ //不含? 所以 -1
if(a[i]>='a' and a[i]<='z'){ //判断1
a1++;
}
else if(a[i]>='0' and a[i]<='9'){ //判断2
a2++;
}
else{ //否则其它字符
a3++;
}
}
cout<<"Letters="<<a1<<endl;
cout<<"Digits="<<a2<<endl;
cout<<"Others="<<a3<<endl;
return 0;
}
这里空空如也



有帮助,赞一个