POJ 2136 Vertical Histogram(垂直直方图)
2014-07-13 12:14
232 查看
Vertical Histogram
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
Sample Output
Source
USACO 2003 February Orange
题目大意:
输入四行大写字母的文本,统计每个字母出现的频率。用垂直柱状图显示。
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17233 | Accepted: 8341 |
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!*/
相关文章推荐
- Poj 2136 Vertical Histogram(打印垂直直方图)
- Poj 2136 Vertical Histogram(打印垂直直方图)
- poj&nbsp;百炼&nbsp;2800:垂直直方图
- poj 百练2800 垂直直方图
- POJ 2800 垂直直方图 解题报告
- poj:垂直直方图
- POJ 百炼 保研机试 2800:垂直直方图
- POJ 2136 Vertical Histogram 打印特殊图形
- 打印输入中单词长度的直方图,垂直方向的。折磨使我强大的一个程序!
- POJ 2136 Vertical Histogram
- poj 2136 Vertical Histogram
- 使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- poj2136
- 读取带空格字符串时候可以用while((c=getchar())!='\n') 2800:垂直直方图
- 打印输入单词长度的直方图 (垂直方向)
- poj_2136
- 单词长度的垂直直方图
- 求全1的最大正方形的边长 和 全1的最大子矩阵的面积 和POJ 2559 最大直方图
- C语言打印水平直方图或者垂直直方图
- poj 2136 打印字母的树状图