题目:
Input
The first line of the input is the number of test cases. Then some test cases followed.
Each test case contains only one line, indicating the string mentioned above.
You can assume there is only lower case letters in the string. The length of the string is more than 0 and no more than 100.
Output
You should output one line for each test case, indicating the most frequent letters. Please note there may be more than one such letter, so you should output all of them, and these letters should be in the same order as the alphabet, that is, 'a', 'b', 'c', 'd' ... 'z'.
Sample Input
2
abcda
tjucstju
Sample Output
a
jtu
代码如下:
#include
int seq[100];
int result[26] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int t[26];
int main()
{
int x, i, j,h=1;
scanf("%d", &x);
getchar();
for (i = 0,j=0; i
{
while (scanf("%c", &seq[j]) != EOF&&seq[j]>=97&&j
{
result[seq[j] - 97]++;
j++;
}
if (j == 0)
{
i = 0;
continue;
}
if (result[0] > result[1])
{
t[0] = 0;
}
else if (result[0] < result[1])
t[0] = 1;
else
{
t[0] = 0;
t[1] = 1;
h = 2;
}
for (j = 2; j < 26; j++)
{
if (result[j]>=result[t[0]])
{
if (result[j] == result[t[0]])
{
t[h] = j;
h++;
}
else
{
t[0] = j;
h = 1;
}
}
}
for (j = 0; j < h; j++)
{
printf("%c", t[j] + 97);
t[j] = 0;
}
printf("\n");
for (j = 0; j < 26; j++)
{
result[j] = 0;
}
i++;
j = 0;
}
return 0;
}