// cs_161_007.c
// http://t...content-available-to-author-only...h.net/test/read.cgi/tech/1354070278/7
#include<stdio.h>
#include<stdlib.h>
#define INPUT_FILE "cs_161_007.c"
#define RANGE (66) // length of scale
#if RANGE < 1
#error RANGE < 1
#endif
int main()
{
FILE *fp;
int i, j;
int counter[26];
int ch;
int sum;
int max_ch_count;
int max_ch_keta;
int hist;
// init
for (i = 0; i < 26; i++) {
counter[i] = 0;
}
sum = 0;
// read & count
if (NULL
== (fp
= fopen(INPUT_FILE
, "r"))) { fprintf(stderr
, "File \"" INPUT_FILE
"\" open error.\n"); }
while (1) {
if (EOF
== (ch
= fgetc(fp
))) { break;
}
if ('a' <= ch && ch <= 'z') {
counter[ch - 'a']++;
sum++;
}
}
// make max_ch_count & max_ch_keta
for (i = max_ch_count = 0; i < 26; i++) {
if (max_ch_count < counter[i]) {
max_ch_count = counter[i];
}
}
max_ch_keta = 1;
i = max_ch_count;
while (i >= 10) {
max_ch_keta++;
i /= 10;
}
// disp scale
printf("File : " INPUT_FILE
"\n"); printf(" max count = %*d\n", max_ch_keta
, max_ch_count
); for (i = 0; i < RANGE; i++) {
}
// show result
for (i = 0; i < 26; i++) {
printf("%c:", (char) (i
+ 'a')); hist = (RANGE * counter[i] + max_ch_count - 1) / max_ch_count;
for (j = 0; j < hist; j++) {
}
for (; j < RANGE; j++) {
}
printf(":%5.1f%%=%*d\n", (double) counter
[i
] / sum
* 100.0, max_ch_keta
, counter
[i
]); }
// end
return 0;
}
// End of cs_161_007.c
Ly8gY3NfMTYxXzAwNy5jCi8vIGh0dHA6Ly90Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5oLm5ldC90ZXN0L3JlYWQuY2dpL3RlY2gvMTM1NDA3MDI3OC83CgojaW5jbHVkZTxzdGRpby5oPgojaW5jbHVkZTxzdGRsaWIuaD4KCiNkZWZpbmUgSU5QVVRfRklMRSAgICJjc18xNjFfMDA3LmMiCiNkZWZpbmUgUkFOR0UgICAgICAgKDY2KSAgICAgICAgLy8gbGVuZ3RoIG9mIHNjYWxlCgojaWYgUkFOR0UgPCAxCiNlcnJvciBSQU5HRSA8IDEKI2VuZGlmCgppbnQgbWFpbigpCnsKICAgIEZJTEUgKmZwOwogICAgaW50IGksIGo7CiAgICBpbnQgY291bnRlclsyNl07CiAgICBpbnQgY2g7CiAgICBpbnQgc3VtOwogICAgaW50IG1heF9jaF9jb3VudDsKICAgIGludCBtYXhfY2hfa2V0YTsKICAgIGludCBoaXN0OwoKICAgIC8vIGluaXQKICAgIGZvciAoaSA9IDA7IGkgPCAyNjsgaSsrKSB7CiAgICAgICAgY291bnRlcltpXSA9IDA7CiAgICB9CiAgICBzdW0gPSAwOwoKICAgIC8vIHJlYWQgJiBjb3VudAogICAgaWYgKE5VTEwgPT0gKGZwID0gZm9wZW4oSU5QVVRfRklMRSwgInIiKSkpIHsKICAgICAgICBmcHJpbnRmKHN0ZGVyciwgIkZpbGUgXCIiIElOUFVUX0ZJTEUgIlwiIG9wZW4gZXJyb3IuXG4iKTsKICAgICAgICBleGl0KDEpOwogICAgfQogICAgd2hpbGUgKDEpIHsKICAgICAgICBpZiAoRU9GID09IChjaCA9IGZnZXRjKGZwKSkpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGlmICgnYScgPD0gY2ggJiYgY2ggPD0gJ3onKSB7CiAgICAgICAgICAgIGNvdW50ZXJbY2ggLSAnYSddKys7CiAgICAgICAgICAgIHN1bSsrOwogICAgICAgIH0KICAgIH0KICAgIGZjbG9zZShmcCk7CgogICAgLy8gbWFrZSBtYXhfY2hfY291bnQgJiBtYXhfY2hfa2V0YQogICAgZm9yIChpID0gbWF4X2NoX2NvdW50ID0gMDsgaSA8IDI2OyBpKyspIHsKICAgICAgICBpZiAobWF4X2NoX2NvdW50IDwgY291bnRlcltpXSkgewogICAgICAgICAgICBtYXhfY2hfY291bnQgPSBjb3VudGVyW2ldOwogICAgICAgIH0KICAgIH0KICAgIG1heF9jaF9rZXRhID0gMTsKICAgIGkgPSBtYXhfY2hfY291bnQ7CiAgICB3aGlsZSAoaSA+PSAxMCkgewogICAgICAgIG1heF9jaF9rZXRhKys7CiAgICAgICAgaSAvPSAxMDsKICAgIH0KCiAgICAvLyBkaXNwIHNjYWxlCiAgICBwcmludGYoIkZpbGUgOiAiIElOUFVUX0ZJTEUgIlxuIik7CiAgICBwcmludGYoIiAgbWF4IGNvdW50ID0gJSpkXG4iLCBtYXhfY2hfa2V0YSwgbWF4X2NoX2NvdW50KTsKICAgIHByaW50ZigiICsiKTsKICAgIGZvciAoaSA9IDA7IGkgPCBSQU5HRTsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCItIik7CiAgICB9CiAgICBwcmludGYoIitcbiIpOwoKICAgIC8vIHNob3cgcmVzdWx0CiAgICBmb3IgKGkgPSAwOyBpIDwgMjY7IGkrKykgewogICAgICAgIHByaW50ZigiJWM6IiwgKGNoYXIpIChpICsgJ2EnKSk7CiAgICAgICAgaGlzdCA9IChSQU5HRSAqIGNvdW50ZXJbaV0gKyBtYXhfY2hfY291bnQgLSAxKSAvIG1heF9jaF9jb3VudDsKICAgICAgICBmb3IgKGogPSAwOyBqIDwgaGlzdDsgaisrKSB7CiAgICAgICAgICAgIHByaW50ZigiKiIpOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgaiA8IFJBTkdFOyBqKyspIHsKICAgICAgICAgICAgcHJpbnRmKCIgIik7CiAgICAgICAgfQogICAgICAgIHByaW50ZigiOiU1LjFmJSU9JSpkXG4iLCAoZG91YmxlKSBjb3VudGVyW2ldIC8gc3VtICogMTAwLjAsIG1heF9jaF9rZXRhLCBjb3VudGVyW2ldKTsKICAgIH0KCiAgICAvLyBlbmQKICAgIHJldHVybiAwOwp9CgovLyBFbmQgb2YgY3NfMTYxXzAwNy5j