POJ 2136 Vertical Histogram 题解(gcc) - 哆啦比猫的技术瞎扯 - Arch Linux · ドラえもん · 实时绘制
POJ 2136 Vertical Histogram 题解(gcc)
http://poj.org/problem?id=2136
#include <stdio.h>
int main(void)
{
// read
unsigned short statistic[26] = {0};
unsigned short max = 0;
int ch;
while ((ch = getchar()) != EOF)
if (ch >= 'A' && ch <= 'Z') {
statistic[ch - 'A']++;
if (statistic[ch - 'A'] > max)
max = statistic[ch - 'A'];
}
// write
char line[26*2+1];
while (max) {
for (ch=0; ch<26; ch++) {
if (statistic[ch] >= max)
line[ch*2] = '*';
else
line[ch*2] = ' ';
line[ch*2+1] = ' ';
}
ch = 25*2+1;
while (line[--ch] == ' ') {}
line[++ch] = 0;
printf("%s\n", line);
max--;
}
for (max=0; max<26; max++)
printf("%c%c", 'A' + max, (max==25 ? '\n' : ' '));
return 0;
}
凡未特殊声明(转载/翻译),所有文章均为原创。
by Giumo Xavier Clanjor (哆啦比猫/兰威举), 2010-2019.
本作品采用知识共享署名·非商业性使用·相同方式共享 3.0 中国大陆许可协议进行许可。
文中凡未特殊声明且未声明为引用的代码均以 MIT 协议授权。
blog comments powered by Disqus