首页 > 代码库 > 【POJ2136】Vertical Histogram(简单模拟)
【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 }
【POJ2136】Vertical Histogram(简单模拟)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。