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

忘记读取后清空数组,也不知道准确的长度。

#include<bits/stdc++.h>
using namespace std;
#define ll long long

char s[2005];
int cnt[26]={};
int maxh=0;

int main(){
    fgets(s,2005,stdin);
    for(int i=0;i<2000;i++){
        if(s[i]>='A'&&s[i]<='Z'){
            cnt[s[i]-'A']++;
        }
        s[i]=' ';
    }
    fgets(s,2005,stdin);
    for(int i=0;i<2000;i++){
        if(s[i]>='A'&&s[i]<='Z'){
            cnt[s[i]-'A']++;
        }
        s[i]=' ';
    }
    fgets(s,2005,stdin);
    for(int i=0;i<2000;i++){
        if(s[i]>='A'&&s[i]<='Z'){
            cnt[s[i]-'A']++;
        }
        s[i]=' ';
    }
    fgets(s,2005,stdin);
    for(int i=0;i<2000;i++){
        if(s[i]>='A'&&s[i]<='Z'){
            cnt[s[i]-'A']++;
        }
        s[i]=' ';
    }


    maxh=*max_element(cnt,cnt+26);
    int curh=maxh;

    while(curh){
        for(int i=0;i<26;i++){
            if(cnt[i]>=curh){
                printf("*");
            }
            else{
                printf(" ");
            }
            if(i!=25){
                printf(" ");
            }
            else{
                printf("\n");
            }
        }
        curh--;
    }
    for(int i=0;i<26;i++){
        char a='A'+i;
        printf("%c",a);
        if(i!=25){
            printf(" ");
        }
        else{
            printf("\n");
        }
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2022-02-27
  • 2022-01-09
  • 2022-03-09
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2021-08-12
  • 2022-12-23
  • 2021-10-30
  • 2022-02-08
相关资源
相似解决方案