#include <stdio.h>
#include <stdlib.h>
int compare(const void *a, const void *b) {
return (*(int *)a - *(int *)b);
}
int main() {
int numbers[20], n = 0, num;
char input[10];
// รับค่าตัวเลขจนกว่าจะใส่ "stop"
while (1) {
// ตรวจสอบการหยุดการรับข้อมูล
if (input[0] == 's' && input[1] == 't' && input[2] == 'o' && input[3] == 'p' && input[4] == '\0') {
break;
}
num
= atoi(input
); // แปลงสตริงเป็นตัวเลข
// ตรวจสอบว่ามีตัวเลขซ้ำหรือไม่
int is_duplicate = 0;
for (int i = 0; i < n; i++) {
if (numbers[i] == num) {
is_duplicate = 1;
break;
}
}
// ถ้าไม่มีตัวเลขซ้ำ ให้เพิ่มลงใน array
if (!is_duplicate) {
numbers[n++] = num;
}
}
// เรียงลำดับตัวเลข
qsort(numbers
, n
, sizeof(int), compare
);
// แสดงผลลัพธ์ที่เรียงแล้ว
for (int i = 0; i < n; i++) {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBjb21wYXJlKGNvbnN0IHZvaWQgKmEsIGNvbnN0IHZvaWQgKmIpIHsKICAgIHJldHVybiAoKihpbnQgKilhIC0gKihpbnQgKiliKTsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgbnVtYmVyc1syMF0sIG4gPSAwLCBudW07CiAgICBjaGFyIGlucHV0WzEwXTsKCiAgICAvLyDguKPguLHguJrguITguYjguLLguJXguLHguKfguYDguKXguILguIjguJnguIHguKfguYjguLLguIjguLDguYPguKrguYggInN0b3AiCiAgICB3aGlsZSAoMSkgewogICAgICAgIHNjYW5mKCIlcyIsIGlucHV0KTsKCiAgICAgICAgLy8g4LiV4Lij4Lin4LiI4Liq4Lit4Lia4LiB4Liy4Lij4Lir4Lii4Li44LiU4LiB4Liy4Lij4Lij4Lix4Lia4LiC4LmJ4Lit4Lih4Li54LilCiAgICAgICAgaWYgKGlucHV0WzBdID09ICdzJyAmJiBpbnB1dFsxXSA9PSAndCcgJiYgaW5wdXRbMl0gPT0gJ28nICYmIGlucHV0WzNdID09ICdwJyAmJiBpbnB1dFs0XSA9PSAnXDAnKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KCiAgICAgICAgbnVtID0gYXRvaShpbnB1dCk7ICAvLyDguYHguJvguKXguIfguKrguJXguKPguLTguIfguYDguJvguYfguJnguJXguLHguKfguYDguKXguIIKCiAgICAgICAgLy8g4LiV4Lij4Lin4LiI4Liq4Lit4Lia4Lin4LmI4Liy4Lih4Li14LiV4Lix4Lin4LmA4Lil4LiC4LiL4LmJ4Liz4Lir4Lij4Li34Lit4LmE4Lih4LmICiAgICAgICAgaW50IGlzX2R1cGxpY2F0ZSA9IDA7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaWYgKG51bWJlcnNbaV0gPT0gbnVtKSB7CiAgICAgICAgICAgICAgICBpc19kdXBsaWNhdGUgPSAxOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIC8vIOC4luC5ieC4suC5hOC4oeC5iOC4oeC4teC4leC4seC4p+C5gOC4peC4guC4i+C5ieC4syDguYPguKvguYnguYDguJ7guLTguYjguKHguKXguIfguYPguJkgYXJyYXkKICAgICAgICBpZiAoIWlzX2R1cGxpY2F0ZSkgewogICAgICAgICAgICBudW1iZXJzW24rK10gPSBudW07CiAgICAgICAgfQogICAgfQoKICAgIC8vIOC5gOC4o+C4teC4ouC4h+C4peC4s+C4lOC4seC4muC4leC4seC4p+C5gOC4peC4ggogICAgcXNvcnQobnVtYmVycywgbiwgc2l6ZW9mKGludCksIGNvbXBhcmUpOwoKICAgIC8vIOC5geC4quC4lOC4h+C4nOC4peC4peC4seC4nuC4mOC5jOC4l+C4teC5iOC5gOC4o+C4teC4ouC4h+C5geC4peC5ieC4pwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBwcmludGYoIiVkICIsIG51bWJlcnNbaV0pOwogICAgfQoKICAgIHJldHVybiAwOwp9