C++ 排序算法错误修正:患者信息按年龄排序
#include\u003cbits\u002Fstdc++.h\u003e\nusing namespace std;\nstruct patient\n{\n\tstring id;\n\tint age;\n\tint ord;\n};\npatient p[9999999];\nbool cmp(patient a, patient b)\n{\n\tif (a.age != b.age) {\n\t\treturn a.age \u003e b.age;\n\t} else {\n\t\treturn a.ord \u003c b.ord;\n\t}\n}\nint main()\n{\n\tint n;\n\tcin \u003e\u003e n;\n\tfor (int i = 1; i \u003c= n; i++)\n\t{\n\t\tcin \u003e\u003e p[i].id \u003e\u003e p[i].age;\n\t\tp[i].ord = i;\n\t}\n\tsort(p + 1, p + n + 1, cmp);\n\tfor (int i = 1; i \u003c= n; i++)\n\t{\n\t\tcout \u003c\u003c p[i].id \u003c\u003c endl;\n\t}\n\treturn 0;\n}
原文地址: https://www.cveoy.top/t/topic/qCAQ 著作权归作者所有。请勿转载和采集!