编程介的小学生 2020-04-15 17:38 采纳率: 0.4%
浏览 33

An Odd Award Rule 奇怪的规则

Problem Description
The education of primary school in China is a big problem now. A teacher must be very careful not only when he/she is criticizing the students, but also when he/she is giving awards to good students. Teacher Liu always gave the top ten students on his examination some little awards before, but some parents are a little bit angry about this now. They say that their little kids may get hurt because they will never get the awards. Teacher Liu has to change his award rule. He wants all students have a chance to win the awards, no matter their scores are good or poor. But he still wants good students to get more chance. So the new rule seems a little bit odd: anyone whose score equals to the sum of the scores of OTHER 3 or 2 students, will win the award. Now figuring out who is qualified for the awards seems a little bit hard for Teacher Liu. As the monitor of his class and a little programmer, you should help him to do this.

Input
For each test case, first print an integer in a line, indicating how many students win the awards. Then print the names of those who win the awards in alphabetic order, each name in a line.

Output
For each test case, print one line containing an integer which equals to the formula’s value mod P.

Sample Input
1
5
SIKE 12
WORRY 20
LUCENT 8
KILI 3
TOM 1

Sample Output
2
SIKE
WORRY

展开全部

  • 写回答

2条回答 默认 最新

  • 码农阿豪@新空间 Java领域优质创作者 2024-07-25 07:22
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    To solve this problem, we can create a list of tuples to store the student names and their scores. Then we can iterate through the list, calculate the sum of scores of other students for each student, and check if the student meets the criteria to win the award. Finally, we can sort the list of winners alphabetically and print the results. Here is the Python code to implement this:
    # Function to determine if a student qualifies for the award
    def qualifies_for_award(student, students):
        total = sum(score for name, score in students if name != student)
        return student[1] == total
    # Read the number of test cases
    test_cases = int(input())
    for _ in range(test_cases):
        # Read the number of students
        num_students = int(input())
        
        students = []
        
        # Read the names and scores of each student
        for _ in range(num_students):
            name, score = input().split()
            students.append((name, int(score)))
        
        # Find the students who qualify for the award
        winners = [student for student in students if qualifies_for_award(student, students)]
        
        # Sort the winners alphabetically
        winners.sort(key=lambda x: x[0])
        
        # Print the number of winners
        print(len(winners))
        
        # Print the names of the winners
        for winner in winners:
            print(winner[0])
    

    Sample Input:

    1
    5
    SIKE 12
    WORRY 20
    LUCENT 8
    KILI 3
    TOM 1
    

    Sample Output:

    2
    SIKE
    WORRY
    

    展开全部

    评论
  • 你知我知皆知 2024-07-25 07:22
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    # 读取数据
    data <- readLines()
    
    # 解析输入
    n <- as.integer(data[1])
    scores <- data[n+2]
    
    # 计算每个学生的总分
    sum_scores <- sapply(scores, function(x) x + sum(dplyr::filter(scores, id == x)$score))
    
    # 构建一个字典来存储学生和他们的得分
    students <- lapply(1:n, function(i){
      student_id <- i
      total_score <- sum_scores[i]
      if (total_score > n) {
        return(NULL)
      }
      return(list(id = student_id, score = total_score))
    })
    
    # 根据得分条件筛选出获奖的学生
    winners <- dplyr::filter(students, score %in% sum_scores)
    
    # 打印获奖的学生名单
    print(paste("获奖人数:", length(winners), "\n"))
    for (i in 1:length(winners)) {
      winner_id <- winners[[i]]$id
      winner_name <- dplyr::filter(scores, id == winner_id)$name
      print(paste(winner_name, "得奖", sep = ""))
    }
    

    这个代码首先读取输入的数据,并解析成包含学生信息的列表。然后计算每个学生的总分,并根据得分条件筛选出获奖的学生。最后打印出获奖的学生名单。

    展开全部

    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部