前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >POJ 2136 Vertical Histogram(当时写的比较恶心,优化一下)

POJ 2136 Vertical Histogram(当时写的比较恶心,优化一下)

作者头像
风骨散人Chiam
发布2020-10-28 09:41:04
2530
发布2020-10-28 09:41:04
举报
文章被收录于专栏:CSDN旧文

Vertical Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21223 Accepted: 10048 Description

Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text input (no more than 72 characters per line) from the input file and print a vertical histogram that shows how many times each letter (but not blanks, digits, or punctuation) appears in the all-upper-case input. Format your output exactly as shown. Input

  • Lines 1…4: Four lines of upper case text, no more than 72 characters per line. Output
  • Lines 1…??: Several lines with asterisks and spaces followed by one line with the upper-case alphabet separated by spaces. Do not print unneeded blanks at the end of any line. Do not print any leading blank lines. Sample Input

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. THIS IS AN EXAMPLE TO TEST FOR YOUR HISTOGRAM PROGRAM. HELLO! Sample Output

代码语言:javascript
复制
                            *
                            *
        *                   *
        *                   *     *   *
        *                   *     *   *
*       *     *             *     *   *
*       *     * *     * *   *     * * *
*       *   * * *     * *   * *   * * * *
*     * * * * * *     * * * * *   * * * *     * *
* * * * * * * * * * * * * * * * * * * * * * * * * *

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

Source

USACO 2003 February Orange 题意很简单,统计每个字母的个数,但是打印起来比较麻烦,签到题。

代码语言:javascript
复制
#include<iostream>
#include<map>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
char a[100];
char  b[100];
char  c[100];
char  d[100];
int  ob[25];
int main()
{
    int ans=0;
    memset(ob,0,sizeof(ob));
    gets(a);
    gets(b);
    gets(c);
    gets(d);
    for(int i=0;i<100;i++){
    if(a[i]>='A'&&a[i]<='Z') ob[a[i]-'A'+1]++;
    if(b[i]>='A'&&b[i]<='Z') ob[b[i]-'A'+1]++;
    if(c[i]>='A'&&c[i]<='Z') ob[c[i]-'A'+1]++;
    if(d[i]>='A'&&d[i]<='Z') ob[d[i]-'A'+1]++;
    }
    for(int i=0;i<=26;i++)
    ans=max(ob[i],ans);
    for(int i=ans;i>=1;i--){
    for(int j=1;j<=26;j++)
    if(ob[j]>=i)cout<<"* ";
    else cout<<"  ";
    cout<<endl;
    }
    for(int j=0;j<=25;j++)
    {
        cout<<char(j+'A')<<' ';
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/06/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档