P1598 垂直柱状图

P1598 垂直柱状图

题目链接:https://www.luogu.org/problem/P1598

代码:

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

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t[100]={0},b1,c1,d1,a1,i;
    char a[1000],b[1000],c[1000],d[1000];
    gets(a);
    gets(b);
    gets(c);
    gets(d);
    a1 = strlen(a);
    b1 = strlen(b);
    c1 = strlen(c);
    d1 = strlen(d);
    for(i=0;i<a1;i++){
      if(a[i]>=65&&a[i]<=90){
         t['Z'-a[i]]++;   
       }
    }
    for(i=0;i<b1;i++){
      if(b[i]>=65&&b[i]<=90){
         t['Z'-b[i]]++;
       }
    }
    for(i=0;i<c1;i++){
      if(c[i]>=65&&c[i]<=90){
         t['Z'-c[i]]++;
       }
    }
    for(i=0;i<d1;i++){
      if(d[i]>=65&&d[i]<=90){
         t['Z'-d[i]]++;
       }
    }
    int l[30],max=0,j;
    for(i=0;i<26;i++){
        l[i] = t[25-i];   //注意,因为两数相减所以将数存进t的数组时相反;
        if(l[i]>max){  
            max = l[i];   //找到柱状图的高;
        }
    }
    int p =max;
    for(i=0;i<max;i++){
        for(j=0;j<26;j++){
            if(l[j]>=p){
                cout<<"* ";
            }else{
                cout<<"  ";
            }
        }
        cout<<endl;
        p--;
    }
    for(i=0;i<26;i++){
        printf("%c ",'A'+i);
    }
    return 0;
}
posted @ 2019-07-26 21:15  幽灵小一只  阅读(280)  评论(0编辑  收藏  举报