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')<<' ';
        }
    }
    
    
  • 相关阅读:
    Android Studio复制项目作为一个新的工程
    7-(基础入门篇)关于STM32底层程序使用说明
    6-(基础入门篇)学会编译lua固件,固件的合成
    5-(基础入门篇)学会刷Wi-Fi模块固件(刷LUA版本固件)
    STM32嵌入LUA开发(控制小灯闪耀)
    1-添加自己的Lua执行函数(ESP8266-SDK开发(lua版本))
    android 权限动态申请
    Android应用更新-自动检测版本及自动升级
    Android中AsyncTask的使用
    关于TCP和MQTT之间的转换
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12798863.html
Copyright © 2011-2022 走看看