《算法竞赛入门经典》第一章1.4
代码1-11
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,n,m; 5 scanf("%d%d",&n,&m); 6 a=(4*n-m)/2; 7 b=n-a; 8 if(n%2==1||a<0||b<0) 9 printf("No answer\n"); 10 else 11 printf("%d %d",a,b); 12 return 0; 13 }
程序1-12
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c; 5 scanf("%d%d%d",&a,&b,&c); 6 if(a<b&&b<c)printf("%d %d %d",a,b,c); 7 if(a<c&&c<b)printf("%d %d %d",a,c,b); 8 if(b<a&&a<c)printf("%d %d %d",b,a,c); 9 if(b<c&&c<a)printf("%d %d %d",b,c,a); 10 if(c<a&&a<b)printf("%d %d %d",c,a,b); 11 if(c<b&&b<a)printf("%d %d %d",c,b,a); 12 return 0; 13 }
程序1-13 三整数排序
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c; 5 scanf("%d%d%d",&a,&b,&c); 6 if(a<=b&&b<=c)printf("%d %d %d",a,b,c); 7 else if(a<=c&&c<=b)printf("%d %d %d",a,c,b); 8 else if(b<=a&&a<=c)printf("%d %d %d",b,a,c); 9 else if(b<=c&&c<=a)printf("%d %d %d",b,c,a); 10 else if(c<=a&&a<=b)printf("%d %d %d",c,a,b); 11 else if(c<=b&&b<=a)printf("%d %d %d",c,b,a); 12 return 0; 13 }
程序1-14 三整数排序(3)
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c,t; 5 scanf("%d%d%d",&a,&b,&c); 6 if(a>b){t=a;a=b;b=t;} 7 if(a>c){t=a;a=c;c=t;} 8 if(b>c){t=b;b=c;c=t;} 9 printf("%d %d %d",a,b,c); 10 return 0; 11 }