Talk is cheap. Show me the code. —— Linus Torvalds
#include<iostream>#include<cstdio>#include<cmath>usingnamespace std;typedeflonglong ll;constint MAX =1010;const ll INF =9999999999;int n, a[MAX];voiddeal(int num){
ll ans, b, d;ll c = INF;for(int i =0; i < n -1; i++)for(int j = i +1; j < n; j++){
d = a[i]+ a[j];if((b =abs(d - num))< c){
c = b;ans = d;}}printf("Closest sum to %d is %lld.\n", num, ans);}intmain(){
//freopen("i.txt", "r", stdin);int m, num, t =1;while(scanf("%d",&n), n){
printf("Case %d:\n", t++);for(int i =0; i < n; i++)scanf("%d",&a[i]);scanf("%d",&m);for(int i =0; i < m; i++){
scanf("%d",&num);deal(num);}}return0;}