The questions are:Http://post.baidu.com/F? Kz= 70481398
Count the number of letters:
ProgramEnter a string (up to 100 characters in length), all lowercase letters.
Count the number of occurrences of lower-case letters and use the required graph.
Test data:
Input:
Sadjhasdhqwpopeepomcxnnbladkjkfjasjas
output:
@< BR >< br> @@@@@@
a B c d e f g h I j k l m n o p q r s t u v w x y z
note:
the number of lowercase letters in a string cannot exceed 20.
programming language : C/C ++.
_________________________________________________
The question refers to the number of each letter and the number of @ output above @. I use an array (array int count [26]) with a length of 26 to save the number of each letter, then, a 26*20 array (the number of each letter cannot exceed 20) is used to record the final output result, the initialization in this array is a null character. Every time a letter is encountered, it is assigned a value of @. Finally, you only need to output the array from the highest row down to get the result, however, many of the preceding columns may be empty characters. to output data from the first row containing at least one non-empty character (I .e. @), I used a variable (INT max_count) to record the location of this row. The procedure is as follows:
# I nclude < Iostream >
Using Namespace STD;
# DefineCount 20
Void Output ( Char * P)
{
Char Chars [ 26 ] [Count];
For ( Int I = 0 ; I < 26 ; I ++ )
For ( Int J = 0 ; J < Count; j ++ )
Chars [I] [J] = ' ' ;
IntCount [26];
For(IntI=0; I<26; I++)
Count [I]=0;
Int Max_count = 0 ;
Int Index = 0 ;
Int TMP = 0 ;
While ( * P ! = ' \ 0 ' )
{
Index = * P - ' A ' ;
TMP = ++ Count [Index];
If (Max_count < TMP)
Max_count = TMP;
Chars [Index] [TMP - 1 ] = ' @ ' ;
P ++ ;
}
For ( Int I = Max_count - 1 ; I > = 0 ; I -- )
{
For ( Int J = 0 ; J < 26 ; J ++ )
Cout < Chars [J] [I];
Cout < Endl;
}
For ( Char I = ' A ' ; I <= ' Z ' ; I ++ )
Cout < I;
}
IntMain ()
{
Char *Str="Sadjhasdhqwpopeepomcxnnbladkjkfjasjas",*P=STR;
Output (P );
Getchar ();
Return 0;
}