1 #include <cstdlib>
2 #include <iostream>
3
4 using namespace std;
5
6
7 int main(int argc, char *argv[])
8 {
9 int t,s,a[100],n=0,i,j,k;
10 i=0;
11 while(scanf("%d%d",&a[i],&a[i+1])&&!(a[i]==-1&&a[i+1]==-1))
12 {
13
14
15 a[i]*=a[i+1];a[i+1]-=1;
16 i+=2;
17 }
18
19 n=i;
20 for(i=0;i<n;i+=2)
21 {
22 k=i+1;
23 for(j=i;j<n;j+=2)
24 {
25 if(a[k]<a[j+1])
26 k=j+1;
27 }
28 if(k!=i)
29 {
30 t=a[k];
31 a[k]=a[i+1];
32 a[i+1]=t;
33
34 t=a[k-1];
35 a[k-1]=a[i];
36 a[i]=t;
37
38 }
39 if(a[0]==0)
40 {
41 cout<<a[0];
42 break;
43 }
44 if(a[i]!=0)
45 {
46 cout<<a[i]<<" "<<a[i+1]<<" ";
47 }
48
49 }
50 cout<<endl;
51
52 system("PAUSE");
53 return EXIT_SUCCESS;
54 }
55
posted on 2011-11-09 19:05
刘聪 阅读(262)
评论(0) 编辑 收藏 引用