题目描述:https://blog.csdn.net/qq_23934063/article/details/124722680
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
int high;
int weight;
int sort;
};
int myCmp(const void* a, const void* b) {
struct Node* aa = (struct Node*)a;
struct Node* bb = (struct Node*)b;
if (aa->high != bb->high) {
return aa->high - bb->high;
} else {
return aa->weight - bb->weight;
}
}
void str_handler(char* str_H, char* str_W, struct Node* node) {
char* tmp;
int index = 0;
tmp = strtok(str_H, " ");
node[index].sort = index + 1;
node[index++].high = atoi(tmp);
while (1) {
tmp = strtok(NULL, " ");
if (tmp == NULL) {
break;
}
node[index].sort = index + 1;
node[index++].high = atoi(tmp);
}
index = 0;
tmp = strtok(str_W, " ");
node[index++].weight = atoi(tmp);
while (1) {
tmp = strtok(NULL, " ");
if (tmp == NULL) {
break;
}
node[index++].weight = atoi(tmp);
}
}
int main() {
struct Node* node = NULL;
char str1[1000] = {0};
char str2[1000] = {0};
int num;
scanf("%d", &num);
getchar();
node = (struct Node*)malloc(sizeof(struct Node) * num);
gets(str1);
gets(str2);
str_handler(str1, str2, node);
qsort(node, num, sizeof(node[0]), myCmp);
for (int i = 0; i < num - 1; i++) {
printf("%d ", node[i].sort);
}
printf("%d\n", node[num - 1].sort);
return 0;
}