Closest Sums
Input: standard input
Output: standard output
Time Limit: 3 seconds
Given is a set of integers and then a sequence of queries. A query gives you a number and asks to find a sum of two distinct numbers from the set, which is closest to the query number.
Input
Input contains multiple cases.
Each case starts with an integer n (1 Input is terminated by a case whose n=0. Surely, this case needs no processing. Output Output should be organized as in the sample below. For each query output one line giving the query value and the closest sum in the format as in the sample. Inputs will be such that no ties will occur. Sample input 312173334315130312331233 12334560Sample output
5
Case 1:Closest sum to 1 is 15.Closest sum to 51 is 51.Closest sum to 30 is 29.Case 2:Closest sum to 1 is 3.Closest sum to 2 is 3.Closest sum to 3 is 3.Case 3:Closest sum to 4 is 4.Closest sum to 5 is 5.Closest sum to 6 is 5.题目大意:给出由一些数字组成的集合,然后再输入一个字, 找出集合中不同的两个数的和最接近输入这个数的值解题思路:先求出这个集合中任意两个数的和,然后进行排序,最后查找。因为数据规模比较小,所以可以一个一个比较。
#include