我遇到了这个棘手的问题。你能指导我解决这个问题吗?除了您提供的编码外,还提供简单易懂的解释;我的意思是,你是怎么做到的(逻辑),解释你在每一步中做了什么以及为什么。这将极大地帮助我提高编码技能和能力。
在课堂上,有一些未知的没有。学生的。最近,他们 考试了,今天老师正在放弃他们的考试副本。 老师想找到大部分人获得的号码 学生和获得该数字的学生人数。
输入规范 :第一行包含正整数T(T <= 100)),测试用例数。在你的编码行中,第一个整数将是N - 学生人数。之后N个整数将跟随哪个 学生的标志。学生将获得0到100之间的分数 包容。
输出规范 :对于每种情况,打印案例编号,然后是两个整数,其中第一个是最大频率的数字,然后是 那个标记的频率。如果可以输出几个这样的输出 最大标记的那个。
我尝试了一些......虽然无效......
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main ()
{
int stud_no;
clrscr();
printf("\nEnter the total no. of students:");
scanf("%d", &stud_no);
printf("%d", stud_no);
// Can't go on more
/* Need Help*/
getchar();
return 0;
}
答案 0 :(得分:3)
If I understand the requirements, your input looks something like this:
3
5 90 91 75 34 78
4 20 20 45 78
6 87 44 73 91 91 90
You have 3 test cases: test case 1 gives the scores for 5 students, test case two gives the scores for 4 students, and test case 3 gives the scores for 6 students.
For each test case, you print out the maximum score and the number of times that score appears:
Test case 1: max score = 91, number of students = 1 out of 5
Test case 2: max score = 78, number of students = 1 out of 4
Test case 3: max score = 91, number of students = 2 out of 6
or something along those lines.
So, you need to think in terms of the following operations:
You should not need to use any arrays for this; you only need to keep track of the maximum score and the number of times you've seen it for any given test case.
Now, if you have a specific problem with any of the above steps, please ask, and we'll do what we can to steer you in the right direction. But nobody's going to write your code for you. You have to show us what you've done.
答案 1 :(得分:0)
#include <stdio.h>
int main(void){
int T;
scanf("%d", &T);
for(int i = 1; i <= T; ++i){
int marks[101] = {0};
int max = -1;
int n, mark;
scanf("%d", &n);
for(int j = 0; j < n; ++j){
scanf("%d", &mark);
if(mark > max)
max = mark;
++marks[mark];
}
printf("case %d : max = %d, frequency = %d\n", i, max, marks[max]);
}
getchar();
return 0;
}