参考代码:
#include <iostream> #include <string> #include <cctype> using std::cin; using std::cout; using std::endl; using std::string; void differCharacter(const string& str); int main(void) { string str; getline(cin, str); //整行输入,包含空格 differCharacter(str); return 0; } void differCharacter(const string& str) { unsigned int alpha=0, digit=0, space=0, other=0; for (unsigned int i=0; i<str.length(); i++) { if ( isalpha(str.at(i)) ) { alpha++; } else if ( isdigit(str.at(i)) ) { digit++; } else if ( isspace(str.at(i)) ) { space++; } else { other++; } } cout << alpha << " " << digit << " " << space << " " << other << endl; }
0.0分
2 人评分
C语言训练-8除不尽的数 (C语言代码)暴力解法,答案只有一个,直接输出就好了浏览:1013 |
C语言训练-求PI* (C语言代码)浏览:883 |
蓝桥杯历届试题-九宫重排 (C++代码)浏览:2782 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:896 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:587 |
A+B for Input-Output Practice (II) (C语言代码)浏览:989 |
1017题解浏览:571 |
DNA (C语言代码)浏览:390 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:508 |
输入输出格式练习 (C语言代码)浏览:743 |