-
Notifications
You must be signed in to change notification settings - Fork 1
/
uva_10487-closet_sum.cpp
52 lines (40 loc) · 1001 Bytes
/
uva_10487-closet_sum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
int n, num, ncnt=1;
while(cin>>n && n)
{
vector<long long int> ara;
cout<<"Case "<<ncnt++<<":"<<endl;
long long int temp,uttor,tnum, gnum,value,i;
value;
ara.empty();
for( value = 0; value < n; value++ )
{
cin>>temp;
ara.push_back(temp);
}
cin>>num;
while(num--)
{
cin>>gnum;
uttor=ara[0]+ara[1];
for( value = 0; value < n; value++ )
{
for( i = value+1; i < n; i++ )
{
tnum = ara[value] + ara[i];
if( abs(uttor - gnum) > abs(tnum - gnum))
{
uttor = tnum;
}
}
}
cout<<"Closest sum to "<<gnum<<" is "<<uttor<<"."<<endl;
}
}
return 0;
}