Hust oj 1629 统计图(水题)

统计图
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 139(56 users)Total Accepted: 61(51 users)Rating: Special Judge: No
Description

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

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(" ");
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值