C言語なら、オレに聞け! <5>

このエントリーをはてなブックマークに追加
932デフォルトの名無しさん
>>931
まぁ高速化はいろいろあるけど。基本は数えるんだな。
#include <stdio.h>

int n[256];

main()
{
    char *p = "Hikky";
    int i;
    
    while (*p) {
        n[*p++ & 0xff]++;
    }
    
    for (i = 0; i < 256; i++) {
        if (n[i]) {
            printf("%c: %d\n", i, n[i]);
        }
    }
    
    return 0;
}
933sage:01/09/03 22:29 ID:Lup6D7xc
static int hg[26+1] = {0,};
char *p = "Hikky";
while (*p) {
if (isalpha(*p)) hg[toupper(*p)-'A']++;
p++;
}
934sage:01/09/03 22:30 ID:Lup6D7xc
一行抜けた。うごくからいいか。