Description
Give a string of characters, asking for the number of letters, numbers, spaces, and other characters to be counted. Letters: A, B, ..., z, A, b, ..., z compose numbers: 0, 1, ..., 9 spaces: "" (not including quotation marks) the remainder of the printable word embox to other characters.
Input
There are several sets of test data. Each group of data is one line (not more than 100000). Data to end of file (EOF).
Output
Each set of inputs corresponds to a row of output. Includes four integers a B c D, representing the number of letters, numbers, spaces, and other characters, respectively.
#include <iostream> #include <cstdio>using namespace Std;int main () { char a[81]; int n,b,c,d; while (gets (a)) { n=b=c=d=0; for (int i=0;a[i]!= ' n '; i++) { if (a[i]>= ' 0 ' &&a[i]<= ' 9 ') n++; else if ((a[i]>= ' a ' &&a[i]<= ' z ') | | (a[i]>= ' A ' &&a[i]<= ' Z ')) b++; else if (a[i]== ') C + +; else d++; } cout<<b<< ' <<n<< ' <<c<< ' <<d<<endl; } return 0;}
Learn to Harvest: the input string can be a,cin>>a with string, write the top file # include <string> can, or use char a[81],gets (a), write the top file # include < Cstdio> can do it. Experience: The more write more self-confidence, continue to refuel it, first solve small problems, lay a good foundation!
C + + brush question--1910: character statistics