intmain(){ int n, m; //2.进行瓜堆信息的录入 scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i){ scanf("%d", &wm[i].cnt); wm[i].num = i + 1; } //3.利用sort函数对node自定义类型按照瓜的数量num进行排序 sort(wm, wm + n, cmp); for(int i = 0; i < m; ++i){ int temp; int l = 0, r = n - 1; int flag = 0; scanf("%d", &temp); //4.利用二分查找在瓜堆中查找,如果找到输出瓜堆数量num,否则输出0 while(l <= r){ int mid = (l + r) / 2; if(wm[mid].cnt == temp){ printf("%d\n", wm[mid].num); flag = 1; break; }elseif(wm[mid].cnt > temp){ r = mid - 1; }else{ l = mid + 1; } } if(flag == 0){ printf("0\n"); } } return0; }