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;
}