非常要注意输出格式!!!
描述
Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text input (no more than 72 characters per line) from the input file and print a vertical histogram that shows how many times each letter (but not blanks, digits, or punctuation) appears in the all-upper-case input. Format your output exactly as shown.
输入
Lines 1..4: Four lines of upper case text, no more than 72 characters per line.
输出
* Lines 1..?: Several lines with asterisks and spaces followed by one line with the upper-case alphabet separated by spaces. Do not print unneeded blanks at the end of any line. Do not print any leading blank lines.
样例输入
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THIS IS AN EXAMPLE TO TEST FOR YOUR
HISTOGRAM PROGRAM.
HELLO!
样例输出
*
*
* *
* * * *
* * * *
* * * * * *
* * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
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
#include <stdio.h>
int main()
{
char str1[72]={'0'};
char str2[72]={'0'};
char str3[72]={'0'};
char str4[72]={'0'};
int zd[26]={0};
gets(str1);
gets(str2);
gets(str3);
gets(str4);
int i;
//printf("%d",(int)(str1[0])-64);
for(i=0;i<288;i++)
{
if(i<72 && str1[i]>='A' && str1[i]<='Z')
zd[(int)(str1[i])-65]+=1;
else if(i>=72 && i<144 && str2[i-72]>='A' && str2[i-72]<='Z')
zd[(int)(str2[i-72])-65]+=1;
else if(i>=144 && i<216 && str3[i-144]>='A' && str3[i-144]<='Z')
zd[(int)(str3[i-144])-65]+=1;
else if(i>=216 && str4[i-216]>='A' && str4[i-216]<='Z')
zd[(int)(str4[i-216])-65]+=1;
}
/*for(i=0;i<26;i++)
{
printf("%d\n",zd[i]);
}*/
int max=0;
for(i=0;i<26;i++)
{
if(zd[i]>max)
{
max=zd[i];
}
}
int j,p=0,k;
for(i=max;i>0;i--)
{
for(j=0;j<26;j++)
{
if(zd[j]>=i)
{
p=j+1;
}
}
for(k=0;k<p;k++)
{
if(zd[k]>=i && k!=p-1)
{
printf("* ");
}
else if(zd[k]<i)
{
printf(" ");
}
else if(k==p-1 && zd[k]>=i)
{
printf("*");
}
}
printf("\n");
}
printf("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");
return 0;
}