Home > Back-end >  Solving a problem
Solving a problem

Time:09-16


Enter a line of characters, the statistics of the English letters, Spaces, the number of Numbers and other characters,

CodePudding user response:

For reference code is not long, written
 
#include
#include

Int main ()
{
Int I=0, len=0, zf=0, sz=0, sp=0, qt=0;
Char STR [1024]={0};
Printf (" please enter the string: \ n ");
Gets (STR);
Len=strlen (STR);

//printf (" len=% d \ n ", len);
//printf (" % s \ n ", STR);

for (i=0; i{
If (STR [I] & gt;='a' & amp; & STR [I] <='z')
Zf++;
Else if (STR [I] & gt;='0' & amp; & STR [I] <='9')
Sz++;
Else if (STR [I]==' ')
Sp++;
The else
Qt++;
}

Printf (" \ n characters in string: % s % d a day, and digital % d a day, and a space there are % d, % d a day, and other \ n ",
STR, zf, sz, sp, qt);

Getchar ();
return 0;
}

CodePudding user response:

#include
#include

using namespace std;

Int main ()
{
string str;
Int size, I, en=0, mn=0, kn=0, on=0;
Char cha.

Cout & lt; <"Both Please input STR:" & lt;
Getline (cin, STR);//read contain Spaces
Size=STR. The size ();

for (i=0; i{
Cha=STR [I];

If ((cha & gt;='a' & amp; & Cha<='z') | | (cha & gt;='A' & amp; & Cha & lt;='Z' en=en + 1));
Else if (==' ') cha kn=kn + 1;
Else if (cha & gt;='0' & amp; & Cha & lt; Mn=='9') mn + 1;

The else on=on + 1;

}
Cout & lt; <"ENLIISH CHAR:" & lt; <"" & lt; Cout & lt; <"MATH CHAR:" & lt; <"" & lt; Cout & lt; <"KEYSPACE CHAR:" & lt; <"" & lt; Cout & lt; <"OTHER CHAR:" & lt; <"" & lt; return 0;
}

  • Related