#include<iostream> #include<cctype> using namespace std; void main() { int n,i; cout<<"输入文本,以@结束.\n"; char ch; int whitespace=0; int digits=0;//数字 int chars=0;//字母 int punct=0;//标点 int others=0; cin.get(ch); while(ch!='@') { if(isalpha(ch)) chars++; else if(isspace(ch)) whitespace++; else if(isdigit(ch)) digits++; else if(ispunct(ch)) punct++; else others++; cin.get(ch); } cout<<chars<<"个字母"<<endl; cout<<whitespace<<"个标准空白字符"<<endl; cout<<digits<<"个数字"<<endl; cout<<punct<<"个标点"<<endl; cout<<others<<"个其他字符"<<endl; }
浙公网安备 33010602011771号