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