Statistics A string contains the number of spaces, English, and numbers # include <iostream>using namespace Std;void processstring (char* s) {int n = strlen (s); int Kg=0;int shuzi=0;int yingwen=0;if (n>0) {for (int a=0;a<n;a++) {if (s[a]== ') kg++;if (s[a]<= ' 9 ' &&s[a] >= ' 0 ') shuzi++;if (s[a]<= ' z ' &&s[a]>= ' a ') yingwen++;if (s[a]<= ' z ' &&s[a]>= ' a ') Yingwen ++;} cout<<s<< "contains the number of spaces:" <<kg<<endl;cout<<s<< "contains numbers:" <<shuzi<<endl ;cout<<s<< "contains the number of English:" <<yingwen<<endl;}} int main () {char s[100];cout<< "Please enter a string:"; Cin.getline (s,100);p rocessstring (s); return 0;}
The space at the end of the string can also be recognized by the effect.
Note: The input string cannot be used Cin>>, because it is automatically intercepted when a space is encountered.
To use CIN. The Getline () function reads the entire row.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Huawei OJ platform Exercises" statistics a string containing the number of spaces, English, numbers