计算机挑战赛11

评定奖学金。奖学金评比方法如下:先计算加权成绩,其中k为课程数,然后按照加权成绩排序(规定所有同学的加权成绩各不相同),根据学生的数量取前10%的同学获得一等奖学金(获奖人数向上取整),输出等奖学金的学生姓名。 按照下面的顺序输入相关信息: (1)输入课程数k(k<10);(2)依次输入k个数据表示k门课程所对应的学分:(3)输入学生数量N(N<100);(4)从第四行开始依次输入N个学生的信息(信息格式:姓名及对应的各门课的成绩)。输入说明:第一行输入整数k;第二行依次输入k个数据;第

计算机挑战赛11

代码:

C++:

#include
#include
#include
using namespace std;
float arr[10];
int main() {
	string res[0x3f3f];
	int k; cin >> k;
	for (auto i = 0; i < k; i++) {
		float num; cin >> num;
		arr[i] = num;
	}
	int n; cin >> n;
	for (auto i = 0; i < n; i++) {
		string name; cin >> name;
		int j = 0;
		int sum = 0;
		while (j < k) {
			int grade;
			cin >> grade;
			sum += grade * arr[j] * 10;
			j++;
		}
		res[sum] = name;
	}
	int res1 = ceil(n * 0.1);
	int j1 = 0;
	for (auto i = 1000; i >= 100; i--) {
		if (res[i] != "") {
			cout << res[i] << endl;
			j1++;
		}
		if (j1 >= res1) {
			break;
		}
	}
	return 0;
}
/*
3
0.3 0.4 0.3
3
abc 80 80 80
bcd 90 90 90
cde 70 70 70
*/

Python:

import math

class Solution:
    def main(self):
        k = int(input())
        grade = [0] * 10
        g1 = map(float, input().split())
        i1 = 0
        for i in g1:
            grade[i1] = i
            i1 += 1
        n = int(input())
        res = [None] * 1001
        for ii in range(n):
            n1 = list(map(str, input().split()))
            sum = 0
            for i0 in range(1, len(n1), 1):
                sum += int(n1[i0]) * grade[i0 - 1] * 10
            sum = int(sum)
            res[sum] = n1[0]
        r = math.ceil(n * 0.1)
        a = 0
        for iii in range(1000, 100, -1):
            if res[iii] is not None:
                print(res[iii])
                a += 1
                if a >= r:
                    break


if __name__ == "__main__":
    solution = Solution()
    solution.main()

Java:

package com.my.gududu;

import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String res[] = new String[0x3f3f];
        int k;
        k = input.nextInt();
        float arr[] = new float[100];
        for (int i = 0; i < k; i++) {
            float num;
            num = input.nextFloat();
            arr[i] = num;
        }
        int n;
        n = input.nextInt();
        for (int i = 0; i < n; i++) {
            String name;
            name = input.nextLine();
            int j = 0;
            int sum = 0;
            while (j < k) {
                int grade;
                grade = input.nextInt();
                sum += grade * arr[j] * 10;
                j++;
            }
            res[sum] = name;
        }
        double res1 = Math.ceil(n * 0.1);
        int j1 = 0;
        for (int i = 1000; i >= 100; i--) {
            if (res[i] != null) {
                System.out.print(res[i] + " ");
                j1++;
            }
            if (j1 >= res1) {
                break;
            }
        }
    }
}

版权声明:如无特殊标注,文章均来自网络,本站编辑整理,转载时请以链接形式注明文章出处,请自行分辨。

本文链接:https://www.shbk5.com/dnsj/73779.html