Vertical Histogram

来源:互联网 发布:office2016激活软件 编辑:程序博客网 时间:2024/06/05 20:58

M - Vertical Histogram
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Submit

Status
Description
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.
Input
* Lines 1..4: Four lines of upper case text, no more than 72 characters per line.
Output
* 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.
Sample Input
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THIS IS AN EXAMPLE TO TEST FOR YOUR
HISTOGRAM PROGRAM.
HELLO!
Sample Output
*
*
* *
* * * *
* * * *
* * * * * *
* * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *


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>#include<string.h>int main(){    int i,j,n,max=0;    char a[4][99],k=0,b[99]={0};    for(i=0;i<4;i++)    {       gets(a[i]);//输入句子    }    for(i=0;i<4;i++)    {        n=strlen(a[i]);        for(j=0;j<n;j++)             b[(int)a[i][j]-'A']++;    }    for(i=0;i<26;i++)//找出最高的数确定画图的行数    {        if(b[i]>max)            max=b[i];    }    for(i=0;i<max;i++)    {        for(j=0;j<26;j++)        {            if(b[j]>=(max-i))//大于max-i就输出*            printf("*");        else            printf(" ");             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\n");}
0 0
原创粉丝点击