统计字符出现次数c语言pta
时间: 2023-12-10 10:04:28 浏览: 146
c语言 统计字符出现次数
以下是统计字符出现次数的C语言代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
int m, i, j, number, max;
char a[10000], b;
scanf("%d", &m);
getchar();
while (m--) {
a[10000] = {};
scanf("%s", a);
getchar();
for (i = 0, max = 0, b = a[i]; a[i] != '\0'; i++) {
for (j = 0, number = 1; a[j] != '\0'; j++)
if (a[i] == a[j] && j != i)
number++;
if ((number > max) + (number == max && a[i] < b) > 0) {
b = a[i];
max = number;
}
}
printf("%c %d\n", b, max);
}
return 0;
}
```
阅读全文