#include <stdio.h> struct data{ int id; int apple; int pear; }; struct data kep[100000]; void Bubble(int n){//需要排序的数量 int i,j; int change=0;//本轮冒泡是否改变顺序 struct data temp; for(i=0;i<n;i++){ for(j=n-1;j>i;j--){ if(kep[j-1].apple<kep[j].apple){ temp = kep[j-1]; kep[j-1] = kep[j]; kep[j] = temp; change = 1; } else if(kep[j-1].apple==kep[j].apple){ if(kep[j-1].pear<kep[j].pear){ temp = kep[j-1]; kep[j-1] = kep[j]; kep[j] = temp; change = 1; } } } } } int main(int argc, char *argv[]) { /* scanf("%d",&kep[1].apple); printf("%d",kep[1].apple); */ int t; int n,m; int i,j; scanf("%d",&t); while(t--){//t组测试数据 scanf("%d %d",&n,&m);//共n个篮子,选择m个篮子 for(i=0;i<n;i++){ kep[i].id = i+1; scanf("%d",&kep[i].apple); scanf("%d",&kep[i].pear); } Bubble(n); /* for(i=0;i<n;i++){ printf("id:%d 苹果:%d 梨:%d\n",kep[i].id,kep[i].apple,kep[i].pear); } */ for(i=0;i<m;i++){ if(i==m-1) printf("%d\n",kep[i].id); else printf("%d ",kep[i].id); } } return 0; } |
Double click to view unformatted code.