Hust oj 1629 统计图(水题)

来源:互联网 发布:液晶电视怎样连接网络 编辑:程序博客网 时间:2024/05/21 06:12
统计图Time Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 139(56 users)Total Accepted: 61(51 users)Rating: Special Judge: NoDescription

用一个直方图统计每个大写字母出现的次数。

Input

本题只有一组测试数据,输入n行,n未知,每行输入一个字符串,每个字符串的长度不会超过100。

Output

输出直方图。

Sample Input

HAPPY NEW YEAR!
WA? PE? RE? TLE? MLE? AC!
BBFFIIQQUUVVZZ ^.^
AN AC A DAY KEEPS THE DOCTOR AWAY~

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

Hint

最后一行没有换行


这个格式我也是醉了。。

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int Maxn = 105;int Inf = 0x3f3f3f;char str[Maxn];int cont[26];int main(){    int t = 4;    int Max = -Inf;    memset(cont,0,sizeof(cont));    while(gets(str) != NULL)    {        int len = strlen(str);        for(int i=0;i<len;i++)        {            if(str[i] >= 'A' && str[i] <= 'Z')            {                cont[str[i]-'A']++;                if(cont[str[i]-'A'] > Max)                {                     Max = cont[str[i]-'A'];                }            }        }    }    for(int i=Max;i>=1;i--)    {        for(int j=0;j<26;j++)        {            if(cont[j] == i)            {                printf("*");                cont[j]--;            }            else                printf(" ");            if(j != 25)                printf(" ");        }        printf("\n");    }    for(int i=0;i<26;i++)    {        printf("%c",i+'A');        if(i != 25)            printf(" ");    }}


0 0
原创粉丝点击