Home > Back-end >  HitSSE difficult: statistical characters
HitSSE difficult: statistical characters

Time:10-12

From the keyboard input line 1 string (enter a maximum of 80 characters per line),
Statistics in the string contains various English lowercase characters and the corresponding number,
* * input format requirements: don't you have any message, direct input line 1 character,
* * output format requirements: output results in alphabetical order, "% c=% d \ n"
Each row of the output one letter of statistical information,
If a letter does not appear, not output the letters of the statistical information,
Such as: input string:
Abc2ed a7bcdcd
Output:
A=2
B=2
C=3
D=3
E=1

Reference answer:
# include & lt; stdio.h>
# define BUFFER_SIZE 80
# define COUNT_SIZE 26
The main ()
{
Char STR [BUFFER_SIZE + 1];//2
Int count [COUNT_SIZE]={0};//2
int i=0;
Gets (STR);//2
for(i=0; STR [I]!='\ 0'; I++)//1
{
If ((STR [I] & gt;='a') & amp; & (STR [I] <)='z')//2
The count [STR [I] - 'a'] + +;//4
}

for(i=0; i{
If (count [I] & gt; 1
0)//{
Printf (" % c=% d \ n ", I + 'a', the count [I]);//2
}
}
}

CodePudding user response:

 # include & lt; stdio.h> 
# include & lt; Ctype. H>

# define BUFFER_SIZE 80
# define COUNT_SIZE 26

Int main (void)
{
Char STR [BUFFER_SIZE + 1];//2
Int count [COUNT_SIZE]={0};//2
int i=0;
//gets (STR);//2
The fgets (STR, sizeof (STR), stdin);//2
//for (I=0; STR [I]!='\ 0'; I++)//1
for(i=0; STR [I]; I++)//1
{
//if ((STR [I] & gt;='a') & amp; & (STR [I] <)='z')//2
If (islower (STR [I]))//2
The count [STR [I] - 'a'] + +;//4
}

for(i=0; i{
//if the count [I] & gt; 1
0)//If (count [I])//1
//{
Printf (" % c=% d \ n ", I + 'a', the count [I]);//2
//}
}
}

For your reference ~
  • Related