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 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿