C/C++の宿題を片付けます 110代目at TECH
C/C++の宿題を片付けます 110代目 - 暇つぶし2ch559:デフォルトの名無しさん
08/06/24 04:14:08
>>558
空白、アルファベット以外は出現順
#include <stdio.h>
#include <string.h>

void alphabetsort(char *dst, const char *src)
{
int count[256] = {0}, idx, i;
char *p, label[256] = " aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
idx = strlen(label);
for( ; *src != '\0'; src++){
p = strchr(label, *src);
if(p) count[p - label]++;
else{ label[idx] = *src; count[idx] = 1; idx++; }
}
for(i = 0; i < 256; i++) while(count[i]-- > 0){ *dst = label[i]; dst++; }
*dst = '\0';
}

int main(void)
{
char buf[100], dst[100], *p;
fgets(buf, sizeof(buf), stdin);
p = strchr(buf, '\n');
if(p) *p = '\0';
alphabetsort(dst, buf);
printf("%s\n", dst);
return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch