#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
long long int N,M,arr[10000],i,j,a,b,c;
while(scanf("%lld",&N)==1)
{
for(i=0; i<N; i++)
{
scanf("%lld",&arr[i]);
}
scanf("%lld",&M);
sort(arr,arr+N);
b=0;
c=0;
for(i=0; i<N; i++)
{
for(j=i+1; j<N; j++)
{
a=arr[i]+arr[j];
if(a==M)
{
b=arr[i];
c=arr[j];
}
}
}
printf("Peter should buy books whose prices are %lld and %lld.\n\n",b,c);
}
return 0;
}
#include<algorithm>
using namespace std;
int main()
{
long long int N,M,arr[10000],i,j,a,b,c;
while(scanf("%lld",&N)==1)
{
for(i=0; i<N; i++)
{
scanf("%lld",&arr[i]);
}
scanf("%lld",&M);
sort(arr,arr+N);
b=0;
c=0;
for(i=0; i<N; i++)
{
for(j=i+1; j<N; j++)
{
a=arr[i]+arr[j];
if(a==M)
{
b=arr[i];
c=arr[j];
}
}
}
printf("Peter should buy books whose prices are %lld and %lld.\n\n",b,c);
}
return 0;
}
0 comments: (+add yours?)
Post a Comment