题解 | #字符个数统计#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include #include
using namespace std;
int main() { string a; getline(cin,a); int yingwen=0; int kongge=0; int shuzi=0; int qita=0;
for(int i=0;i<a.length();i++)
{
if(isalpha(a[i]))
yingwen++;
else if(a[i]==' ')
kongge++;
else if(isalnum(a[i]))
shuzi++;
else
qita++;
}
cout<<yingwen<<endl<<kongge<<endl<<shuzi<<endl<<qita<<endl;
}