URAL 2035 

输入x,y,c,  找到任意一对a,b 使得a+b==c&& 0<=a<=x && 0<=b<=y

注意后两个条件,顺序搞错wa几次

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 int main(){
 5     int x,y,c;
 6     while(~scanf("%d%d%d",&x,&y,&c)){
 7         if(x+y<c){
 8             puts("Impossible");
 9             continue;
10         }
11         int a,b;
12         bool s=false;
13         if(x>y){
14             s=true;
15             swap(x,y);
16         }
17         if(x>=c){
18             a=c;
19             b=0;
20         }
21         else{
22             a=x;
23             b=c-x;
24         }
25         if(s) swap(a,b);
26         printf("%d %d\n",a,b);
27     }
28     return 0;
29 }
View Code

相关文章:

  • 2021-12-15
  • 2021-10-06
  • 2021-07-23
  • 2021-04-02
  • 2022-02-19
  • 2021-06-17
  • 2021-11-07
  • 2021-09-11
猜你喜欢
  • 2021-10-07
  • 2021-12-11
  • 2021-10-05
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案