某校进行了一场月考,考试科目为:物理、化学、生物,每科的满分都是一百分。考试结束后老师想找出理科综合能力较强的3名同学参加竞赛,各科权重为40%,35%,25%,按权重计算总分(加权总分结果四舍五入保留到小数第一位)。若总分相同则按照物理、化学、生物优先级进行得分高低的排序。 输入: 第一行,一个整数n,表示参加考试的学生的数量。3<=N<=500。 接下来n行,每行第一个为学生学号(8位数字),后面跟着三个用空格隔开的整数,分别表示该学生三个科目的得分情况,每个整数都是0到100之间。 输出: 分三行分别输出理科综合能力较强的3名同学的学号信息及加权后的总分(保留到小数点后1位)。
样例输入:
5
20200001 93 79 84
20200002 97 86 88
20200003 78 95 78
20200004 76 84 86
20200005 65 84 94
样例输出:
20200002 90.9
20200001 85.9
20200003 84.0
代码:
C++:
cpp
#include<iostream>
#include<cstdio>
using namespace std;
int book[500] = { 0 };
int main() {
int n; cin >> n;
for (int i = 0; i < n; i++) {
int l, h, s;
int id;
cin >> id >> l >> h >> s;
int sum = l + h + s;
book[sum] = id;
}
int count = 0;
for (int i = 300; i >= 0; i--) {
if (count < 3 && book[i] != false) {
cout << book[i];
printf(" %.1f", i * 1.0 / 3);
cout << endl;
count++;
}
}
return 0;
}
/*
5
20200001 93 79 83
20200002 97 86 88
20200003 78 95 78
20200004 76 84 86
20200005 65 84 94
*/
Python:
python
def main():
n = int(input())
book = [0] * 500
for i in range(n):
id, l, h, s = map(int, input().split())
sum = l + h + s
book[sum] = id
count = 0
for i in range(300, -1, -1):
if count < 3 and book[i] != 0:
print(id,end=" ")
print("%.1f\n" % (i / 3))
count += 1
if __name__=="__main__":
main()
Java:
java
package com.my.gududu;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int book[] = new int[500];
for (int i = 0; i < n; i++) {
int id = input.nextInt();
int l = input.nextInt();
int h = input.nextInt();
int s = input.nextInt();
int sum = l + h + s;
book[sum] = id;
}
int count = 0;
for (int i = 300; i >= 0; i--) {
if (count < 3 && book[i] != 0) {
System.out.print(book[i] + " ");
System.out.println(String.format("%.1f", (i * 1.0 / 3)));
count++;
}
}
}
}