2873=老--质价比

 1 #include <stdio.h>
 2 #include <string.h>
 3 struct node
 4 {
 5     int w,j;
 6 } th[100],t;
 7 int main()
 8 {
 9     int i,j,n;
10     while(scanf("%d",&n)!=EOF)
11     {
12         for(i=0; i<n; i++)
13         {
14             scanf("%d",&th[i].w);
15         }
16         for(i=0; i<n; i++)
17         {
18             scanf("%d",&th[i].j);
19         }
20         for(i=0; i<n; i++)
21         {
22             for(j=0; j<n-1-i; j++)
23             {
24                 if(th[j].w>th[j+1].w)
25                 {
26                     t=th[j],th[j]=th[j+1],th[j+1]=t;
27                 }
28                 else if(th[j].w==th[j+1].w)
29                 {
30                     if(th[j].j<th[j+1].j)t=th[j],th[j]=th[j+1],th[j+1]=t;
31                 }
32             }
33         }
34         for(i=0; i<n; i++)
35         {
36             printf("%d %d
",th[i].w,th[i].j);
37         }
38     }
39     return 0;
40 }
原文地址:https://www.cnblogs.com/Angfe/p/10448720.html