您的位置:首页 > 其它

POJ 2136 Vertical Histogram(垂直直方图)

2014-07-13 12:14 232 查看
Vertical Histogram

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17233 Accepted: 8341
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
*
*
*                   *
*                   *     *   *
*                   *     *   *
*       *     *             *     *   *
*       *     * *     * *   *     * * *
*       *   * * *     * *   * *   * * * *
*     * * * * * *     * * * * *   * * * *     * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
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

题目大意:

输入四行大写字母的文本,统计每个字母出现的频率。用垂直柱状图显示。

#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
//freopen("r.txt","w",stdout);
string a,a1,a2,a3,a4;
int i,c;
int max;
int sum[26]={0};
getline(cin,a1);
getline(cin,a2);
getline(cin,a3);
getline(cin,a4);
a=a1+a2+a3+a4;
c=a.length();
for(i=0;i<c;i++)
{
++sum[a[i]-'A'];
}
max = sum[0];
for(i=0;i<26;i++)
{
if(sum[i]>max)
max=sum[i];
}
/////////////////////////////////////
int num;
for(;max>0;max--)
{
for(i=25;i>=0;i--)
{
if(sum[i]>=max)
{
num=i;
break;
}
}

for(i= 0;i<26; i++)
{
if(sum[i]>= max)
{
if(i==25)
{
cout<<"*";
break;
}
if(i==num)
{
cout<<"*";
break;
}
else
{
cout<<'*'<<" ";
}

}
else
{
if(i==25)
{
cout<<" ";
break;
}
else
{
cout<<" "<<" ";
}
}
}
cout<<endl;
}

for(i= 0; i< 26; i++)
{
if(i==25)
cout<<char('A'+i);
else
cout<<char('A'+i)<<" ";
}
cout<<endl;
return 0;

}

/*
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. THIS IS AN EXAMPLE TO TEST FOR YOUR HISTOGRAM PROGRAM. HELLO!*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: