牛津大学编程思维挑战赛(The Oxford University Computing Challenge-OUCC)根据难度分为初级、中级、高级和精英级四个等级,分别对应小学,初中和高中。
该学术活动新赛季报名时间已公布,报名通道及学术活动真题开放中!
学术活动时间:
2022年5月8日14:00-15:00(60 分钟)
Sorting Pairs
A set of pairs of integers needs sorting. There are n pairs in the set and the pairs need sorting in ascending order according to the sum of the pair of numbers.
Input format:
An integer, n, indicating the number of pairs of numbers, followed by up to 20 lines of data, each line consisting of two integers.
Output format:
The sorted pairs of numbers, or the string sorted if the set of pairs is already sorted.
Example
Input:
5
0 10
4 10
1 10
3 10
2 10
Output:
0 10
1 10
2 10
3 10
4 10
Constraints:
All numbers are positive integers less than 100.
None of the input data in this task contains pairs of numbers whose sum is the same as any other pair in the same set.
Task:
Write a program that sorts a set of pairs of numbers in ascending order according to the sum of the pair of numbers.
Note: For Java (and similar) programs the grader expects the name of the main class to be: sortingpairs
知识点:
list列表的应用
tuple元组的应用
dict字典的应用
参考代码:
想要获取备赛计划,考前查缺补漏、重点冲刺
欢迎前来扫描二维码咨询【免费领取】历年学术活动真题及解析!
© 2024. All Rights Reserved. 沪ICP备2023009024号-1