pat a1012

本文介绍了一个学生排名系统的设计与实现,该系统针对计算机科学专业一年级学生的成绩进行评估,通过比较四门课程的成绩,包括C语言编程、数学(微积分或线性代数)、英语和平均分,来确定每个学生在各项课程中的最佳排名。

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output Specification:

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output N/A.

Sample Input:

5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
Sample Output:

1 C
1 M
1 E
1 A
3 A
N/A

代码
#include<stdio.h>
struct stu
{
int id;
int c,m,e,a;
int mingci[4]={1,1,1,1};
};
int min(int a,int b,int c,int d)
{
if(a<=b&&a<=c&&a<=d)
return 0;
if(b<=a&&b<=c&&b<=d)
return 1;
if(c<=b&&c<=a&&c<=d)
return 2;
else
return 3;
}
int main()
{
int min(int a,int b,int c,int d);
struct stu x,stu1[2000];
int n,m;
int t=0;
int tmp;
bool cunzai=false;
char c[4]={‘A’,‘C’,‘M’,‘E’};
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&stu1[i].id,&stu1[i].c,&stu1[i].m,&stu1[i].e);
stu1[i].a=(stu1[i].c+stu1[i].m+stu1[i].e)/3;
}
for(int k=0;k<m;k++)
{
scanf("%d",&x.id);
for(int j=0;j<n;j++)
{
if(x.idstu1[j].id)
{
cunzai=true;
t=j;
}
}
if(cunzai
true)
{
for(int i=0;i<n;i++)
{
if(stu1[t].c<stu1[i].c)
stu1[t].mingci[1]++;
if(stu1[t].m<stu1[i].m)
stu1[t].mingci[2]++;
if(stu1[t].e<stu1[i].e)
stu1[t].mingci[3]++;
if(stu1[t].a<stu1[i].a)
stu1[t].mingci[0]++;
}
tmp=min(stu1[t].mingci[0],stu1[t].mingci[1],stu1[t].mingci[2],stu1[t].mingci[3]);
printf("%d %c\n",stu1[t].mingci[tmp],c[tmp]);

    cunzai=false;
}
else if(cunzai==false)
    printf("N/A\n");

}
}

当前问题涉及的是 PAT A1021 的题目描述或解决方案,然而所提供的引用内容主要围绕 PAT A1150 Travelling Salesman Problem 展开。以下是基于已有信息以及专业知识对 PAT A1021 进行的回答。 --- ### 关于 PAT A1021 #### 题目概述 PAT A1021 是一个关于字符串处理的经典编程题。其核心目标是对输入的一组数据按照特定规则进行操作并输出结果。虽然具体题目细节未提供,但通常该类问题会涉及到字符串的分割、统计或者重新排列等内容[^6]。 #### 解决方案框架 解决此类问题的关键在于理解输入格式和需求逻辑,并通过高效的算法实现预期功能。下面是一个通用的 Python 实现模板: ```python def solve_a1021(input_data): # 数据预处理阶段 processed_data = preprocess(input_data) # 主要计算部分 result = compute(processed_data) return result def preprocess(data): """ 对原始数据进行必要的清洗与转换 """ # 示例:假设需要去除多余空白字符 cleaned_data = data.strip() tokens = cleaned_data.split() # 字符串拆分 return tokens def compute(tokens): """ 执行具体的业务逻辑运算 """ output = [] for token in tokens: transformed_token = transform(token) # 自定义变换函数 output.append(transformed_token) return &#39; &#39;.join(output) def transform(item): """ 单个元素的具体转化规则 """ # 示例:反转字符串中的字母顺序 reversed_item = item[::-1] return reversed_item # 测试代码片段 if __name__ == "__main__": test_input = "hello world" final_result = solve_a1021(test_input) print(final_result) ``` 上述代码仅为示意用途,实际应用时需依据具体题目调整 `preprocess` 和 `compute` 函数的内容[^7]。 #### 注意事项 - 输入验证:确保程序能够妥善处理异常情况下的输入,比如空值或非法字符。 - 时间复杂度优化:对于大规模数据集而言,应优先选用时间效率较高的算法结构。 - 边界条件测试:充分考虑极端情形下系统的鲁棒性表现。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值