zoukankan      html  css  js  c++  java
  • POJ 2136 Vertical Histogram(当时写的比较恶心,优化一下)

    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

    • 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<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')<<' ';
        }
    }
    
    
  • 相关阅读:
    vue里面的v-for列表循环
    浅谈Vue.use
    js 限制输入框只能输入数字的问题
    vue computed的执行问题
    前端 html 篇
    函数声明 及 名称问题
    文件读写操作
    异常以及异常处理框架探析
    使用JDBC插入数据到ORACLE,使用标识列自增列
    session超时跃出iframe并跳到登陆页面(转载)
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12798863.html
Copyright © 2011-2022 走看看