本帖最后由 a2860608 于 2016-8-9 15:47 编辑
统计一个字符串里每个字符出现的次数.
char* ch1 = "$%^&(*GDTFCGVHTREWS#56rtyfhgsq12345thjkl;]'[pl,.[iuyt5rf";[C] 纯文本查看 复制代码 char* ch1 = "$%^&(*GDTFCGVHTREWS#56rtyfhgsq12345thjkl;]'[pl,.[iuyt5rf";
int item[128] = {0};
for (int i = 0; i < (int)strlen(ch1); i++)
{
item[ch1[i]]++;
}
for (int i = 0; i < 128; i++) {
if (item[i] != 0) {
printf("%c----%d\n",i,item[i]);
}
}
|