输入一组字符串,输出出现次数最多的字符串及其个数
输入一个整数n(1 <= n <= 100)然后输入n个字符串(长度 <= 1000 ,字符为小写)
例如:
输入:
3
aaa
bb
bb
输出:
bb 2
2021-01-21 14:01
2021-01-21 15:48
程序代码:
#include"stdio.h"
#include"string.h"
int main()
{
int n;
while(~scanf("%d", &n))
{
int s[10001] = {0}, num, max = 0, count = 0;
for(int i = 0; i < n; ++ i)
{
scanf("%d", &num);
s[num] ++;
//printf("%d %d\n", num, s[num]);
if(max <= s[num])
{
if(count < num && s[num] == max)
{
count = num;
continue;
}
if(s[num] > max)
{
max = s[num];
count = num;
}
}
}
printf("%d %d\n", count, max);
}
return 0;
}
2021-01-21 20:27
2021-01-22 10:07