- 注意:必须geline(cin,str)或取一整行
- 否则会转义字符出问题
#include<bits/stdc++.h> using namespace std; int main() { string str; while( getline(cin,str) ) { int solve[4]={0}; for( auto c: str ) { if( isalpha(c) ) { solve[0]++; } else if( ' '==c ) { solve[1]++; } else if( isalnum(c) ) { solve[2]++; } else { solve[3]++; } } for( int i=0; i<4; ++i ) { cout<<solve[i]<<endl; } } return 0; }