Programing/Algorithm

poj 2136 Vertical Histogram

sosal 2014. 5. 7. 18:03
반응형

/*

 http://sosal.tistory.com/
 * made by so_Sal
 */


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<iostream>

#include<string>

#include<algorithm>

#include<vector>

#include<cmath>

using namespace std;


int main(){


int histogram[26] = {0,};

int N=4;

string tmp;

while(N--){

getline(cin,tmp);

for(int i=0;i<tmp.size();i++){

if(tmp[i] < 'A' && tmp[i] > 'Z')

continue;

histogram[tmp[i]-'A']++;

}

}

int max=0;

for(int i=0;i<26;i++){

if(max < histogram[i])

max=histogram[i];

}


for(int i=max;i>0;i--){

for(int j=0;j<26;j++){


if(j < 25){

if(histogram[j] >= i)

cout<<"* ";

else

cout<<"  ";

}

else{

if(histogram[j] >= i)

cout<<"*";

else

cout<<" ";

}

}cout<<endl;

}

for(int j=0;j<26;j++){

cout<<(char)('A'+j);

if(j<25)

cout<<" ";

}cout<<endl;

}

'Programing > Algorithm' 카테고리의 다른 글

poj 1218 THE DRUNK JAILER  (0) 2014.05.07
poj 3176 Cow Bowling  (0) 2014.05.06
poj 2140 Herd Sums  (0) 2014.05.06
algospot - HAMMINGCODE  (0) 2014.05.06
algospot - Divisibility  (0) 2014.05.06