Source:

Description:

Input Specification:

Output Specification:

Sample Input 1:

Sample Output 1:

Sample Input 2:

Sample Output 2:

Keys:

Attention:

  • 所给数字超过了500

Code:

 /*
Data: 2019-07-21 20:01:45
Problem: PAT_A1048#Find Coins
AC: 11:22 题目大意:
给定整数s,从数集中找出a+b=s
*/ #include<cstdio>
const int M=1e3;
int mp[M]={}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,s,t;
scanf("%d%d", &n,&s);
for(int i=; i<n; i++)
{
scanf("%d", &t);
mp[t]++;
}
for(int i=; i<=s/; i++)
{
if(mp[i] && mp[s-i] && i!=s-i)
{
printf("%d %d", i,s-i);
s=;break;
}
}
if(s!= && s%== && mp[s/]>)
printf("%d %d", s/,s/);
else if(s!=)
printf("No Solution"); return ;
}
05-11 18:11
查看更多