HDU2708-模拟题

来源:互联网 发布:jav网络机顶盒怎么样 编辑:程序博客网 时间:2024/05/29 06:52

Vertical Histogram

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1598    Accepted Submission(s): 284

Problem 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 YOURHISTOGRAM 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
 
题意:
        题目意思很明确,给定四组字符串,让你统计四组字符串中每个字符的出现次数,然后,按照样例的格式输出。
PS:
1.输入样例有多组。
2.需要忽略最后一个‘*’的后导空格。
3.每列之间空一个空格。
接下来就是耐心敲代码了。
#include <iostream>#include <string>using namespace std;int letter[300];char str[300],map[300][300];int main(){#ifndef ONLINE_JUDGEfreopen("2.txt","r",stdin);#endifint i,j;while (gets(str))//read four line at one time{memset(letter,0,sizeof letter);for (j=0; str[j]; ++j){if (isupper(str[j]))++letter[str[j]-'A'];}for (i=0; i < 3; ++i){gets(str);for (j=0; str[j]; ++j){if (isupper(str[j]))++letter[str[j]-'A'];}}//end readmemset(map,' ',sizeof map);for (j=0; j < 26; ++j)//calculate how many time letter appears{for (; letter[j] > 0; --letter[j]){map[letter[j]][j+j] = '*';}}for (i=1; ; ++i)//ignore the ending spaces{for (j=52; j >= 0; --j){if (map[i][j] == '*'){map[i][j+1] = '\0';break;}}if (j < 0)break;}while (--i)puts(map[i]);puts("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");}return 0;}


0 0