wwsxyhyy 2016-07-04 11:53 采纳率: 50%
浏览 1047

ACM题,不太理解哪出错了,求帮忙

题目:
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;
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 lammps Gpu加速出错
    • ¥15 关于PLUS模型中kapaa值的问题
    • ¥15 关于博途V17进行仿真时无法建立连接问题
    • ¥15 请问下这个红框里面是什么文档或者记事本编辑器
    • ¥15 机器学习教材中的例题询问
    • ¥15 求.net core 几款免费的pdf编辑器
    • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
    • ¥15 C# P/Invoke的效率问题
    • ¥20 thinkphp适配人大金仓问题
    • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)