【POJ2136】Vertical Histogram(简单模拟)
比较简单,按照样例模拟就好!~
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <cstring> 5 #include <cctype> 6 #include <cmath> 7 #include <algorithm> 8 #include <numeric> 9 #include <vector> 10 #include <map> 11 using namespace std; 12 13 int let[26]; 14 15 int main () { 16 string text = "", in; 17 for (int i = 0 ; i < 4; ++ i) { 18 getline(cin, in); 19 text += in; 20 } 21 //cout << text << endl; 22 memset (let, 0, sizeof (let)); 23 int Max = 0; 24 for (int i = 0; i < text.size(); ++ i) { 25 if (isalpha(text[i])) { 26 let[text[i] - 'A'] ++; 27 Max = max (Max, let[text[i] - 'A']); 28 } 29 } 30 /* 31 for (int i = 0 ; i< 26; ++i) { 32 cout << (char)('A' + i) << ": " << let[i] << endl; 33 } 34 */ 35 //cout << Max << endl; 36 for (int i = 1; i <= Max; ++ i) { 37 string text_line = ""; 38 for (int j = 0 ; j < 26; ++ j) { 39 if (i > Max - let[j]) { 40 text_line += "*"; 41 } else { 42 text_line += " "; 43 } 44 if (j != 25) text_line += " "; 45 } 46 cout << text_line << endl; 47 } 48 puts("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"); 49 return 0; 50 }