加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

P1598 垂直柱状图

发布时间:2020-12-16 10:48:58 所属栏目:百科 来源:网络整理
导读:P1598 垂直柱状图 题目链接:https://www.luogu.org/problem/P1598 代码: #include bits/stdc++.husing 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],

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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读