设为首页 加入收藏

TOP

POJ 2136 Vertical Histogram
2015-11-21 00:59:13 来源: 作者: 【 】 浏览:1
Tags:POJ 2136 Vertical Histogram

分析:很久以前,在《K&R》上面碰到过这个题,只不过比这个复杂一点。。。。

也是水题,没什么说的,注意一下细节,比如输出的格式等,还有就是,一开始用的for循环,每输入一行结束后就直接打印,好郁闷^~_~^

?

?

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

?

?

?

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; int main() { int len,i,j,maxhigh=0; string s; int c[26]; memset(c,0,sizeof(c)); while (cin>>s) { len=s.length(); for(i=0;i
      
       =65 && s[i]<=90) ++c[s[i]-'A']; } for(i=0;i<26;i++) if(maxhigh
       
        0;i--) { for(j=0;j<26;j++) if(c[j]>=i) printf("* "); else printf(" "); printf("\n"); } for(i=0;i<26;i++) { if(i>0) printf(" "); printf("%c",i+'A'); } printf("\n"); return 0; }
       
      
     
    
   
  


?

?

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
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇CSU1660: K-Cycle 下一篇[LeetCode] Word Break

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: