P1598 垂直柱状图

https://www.luogu.org/problemnew/show/P1598#sub

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
    int a[300],maxn=0;
    char c='A';
    memset(a,0,sizeof(a));
    char b[200];
    for(int i=0; i<4; i++)
    {
        gets(b);
        int sizes=strlen(b);
        for(int i=0; i<sizes; i++)
            if(b[i]>='A'&&b[i]<='Z')
                a[b[i]]++;
    }
    for(int i=0; i<26; i++)
        maxn=max(maxn,a['A'+i]);
    for(int i=0; i<maxn; i++)
    {
        for(int S=0; S<26; S++)
        {
            if(a['A'+S]>=(maxn-i))
                printf("* ");
            else
                printf("  ");
        }

        printf("\n");
    }
    for(int i=0; i<26; i++)
        printf("%c ",c+i);
}

之前有一个错误,就是cin>>会在空格处停止输入·string。

猜你喜欢

转载自www.cnblogs.com/fghfghfgh666/p/9254519.html