gpt4 book ai didi

C - 数数{制作程序}

转载 作者:行者123 更新时间:2023-11-30 21:42:14 24 4
gpt4 key购买 nike

我被这个难题困住了。您能指导我解决这个问题吗?除了您提供的编码之外,还应提供简单易懂的解释;我的意思是,你是如何做到的(逻辑),解释一下你在每一步中做了什么以及为什么。这将极大地帮助我提高我的编码技巧和能力。

In a class, there are some unknown no. of students. Recently, they gave an exam and today the teacher is giving away their exam copies. The teacher wants to find the number which is obtained by most of the students and the number of students who obtained that number.

  • Input Specification : The first line contains a positive integer T (T <= 100)), number of test case. In your coding lines, the first integer will be N - the number of students. After that N integers will follow which are the marks of the students. A student will obtain mark between 0 and 100 inclusive.

  • Output Specification : For each case, print the case number, then the two integers where the first one is the number with maximum frequency and then the frequency of that marks. If several such outputs are possible, output the one with the maximum mark.

我尝试了一些东西......但没有效果......

#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;
}

最佳答案

如果我理解要求,您的输入如下所示:

3
5 90 91 75 34 78
4 20 20 45 78
6 87 44 73 91 91 90

您有 3 个测试用例:测试用例 1 给出 5 名学生的分数,测试用例 2 给出 4 名学生的分数,测试用例 3 给出 6 名学生的分数。

对于每个测试用例,您打印出最高分数以及该分数出现的次数:

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

或者类似的东西。

因此,您需要考虑以下操作:

  1. 获取测试用例的数量
  2. 对于每个测试用例,获取分数数量
  3. 阅读分数
  4. 确定最高分数以及该分数出现的次数
  5. 打印该测试用例的结果
  6. 返回2

您不需要为此使用任何数组;您只需要跟踪任何给定测试用例的最高分数以及您看到该分数的次数。

现在,如果您对上述任何步骤有任何具体问题,请询问,我们将尽力引导您走向正确的方向。但没有人会为你编写代码。你必须向我们展示你做了什么。

关于C - 数数{制作程序},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31057522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com