zoukankan      html  css  js  c++  java
  • poj2136

                                                                           Vertical Histogram
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 16999   Accepted: 8238

    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
     1 #include <iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<iomanip>
     5 using namespace std;
     6 int main()
     7 {
     8     char str1[72],str2[72],str3[72],str4[74];
     9     while(gets(str1))
    10     {
    11         gets(str2);
    12         gets(str3);
    13         gets(str4);
    14         int number[26];
    15         int maxnum=0;
    16         memset(number,0,sizeof(number)); //这句话一定要加上去,不要以为定义完数组后就会自动填充为0
    17         for(int i=0;i<strlen(str1);i++)
    18         {
    19             if(str1[i]==' '||str1[i]<'A'||str1[i]>'Z')
    20                 continue;
    21             int j = (int)str1[i]-65;
    22             number[j]=number[j]+1;
    23             if(number[j]>maxnum)
    24                 maxnum = number[j];
    25         }
    26         for(int i=0;i<strlen(str2);i++)
    27         {
    28             if(str2[i]==' '||str2[i]<'A'||str2[i]>'Z')
    29                 continue;
    30             int j = (int)str2[i]-65;
    31             number[j]++;
    32             if(number[j]>maxnum)
    33                 maxnum = number[j];
    34         }
    35         for(int i=0;i<strlen(str3);i++)
    36         {
    37             if(str3[i]==' '||str3[i]<'A'||str3[i]>'Z')
    38                 continue;
    39             int j = (int)str3[i]-65;
    40             number[j]++;
    41             if(number[j]>maxnum)
    42                 maxnum = number[j];
    43         }
    44         for(int i=0;i<strlen(str4);i++)
    45         {
    46             if(str4[i]==' '||str4[i]<'A'||str4[i]>'Z')
    47                 continue;
    48             int j = (int)str4[i]-65;
    49             number[j]++;
    50             if(number[j]>maxnum)
    51                 maxnum = number[j];
    52         }
    53         int temp = maxnum,flag=0;
    54         for(int j = 0;j<temp;j++)
    55         {
    56             flag=0;
    57             for(int m=0;m<26;m++)
    58                 if(number[m]==maxnum)
    59                 {
    60                     flag = m;
    61                 }
    62             for(int k =0;k<26;k++)
    63             {
    64 
    65                 if(number[k]!=0&&number[k]==maxnum)
    66                 {
    67                     if(flag==k)
    68                     {
    69                         printf("*");
    70                         number[k]--;
    71                         break;
    72                     }
    73                     else printf("* ");
    74                     number[k]--;
    75                 }
    76                 else
    77                 {
    78                     cout<<"  ";
    79                 }
    80             }
    81             printf("
    ");
    82             maxnum--;
    83         }
    84         char c='A';
    85         for(int i=0;i<25;i++)
    86             printf("%c ",c++);
    87         printf("%c
    ",c);
    88 
    89     }
    90     return 0;
    91 }

    这题被搞的没心情了,很简单的一题,结果那个输出结果每一行最后一个星号后面不能有空格,弄的我wa半天,改写了各种代码,总是过不了,后来看了看了讨论区,有种想吐血的冲动。

  • 相关阅读:
    认识jeecms开源项目
    初识eclipse及配置相关
    Html5 Video的使用
    实现渐变色案例
    区域路由的注册机制
    MVC特性路由的提供机制
    再谈async与await
    同步 VS 异步
    C#多线程中的异常处理
    C#多线程基础
  • 原文地址:https://www.cnblogs.com/jhldreams/p/3754195.html
Copyright © 2011-2022 走看看