BUPT-homework/semester3/pset4/7-2-How-to-Place-the-Mail.c

28 lines
487 B
C
Raw Normal View History

2022-10-30 20:57:06 +08:00
#include <stdio.h>
#include <stdlib.h>
void insert(long long *box, long long val, int i) {
int loc = (val + i * i) % 10;
if (loc < 10 && box[loc] == 0) {
box[loc] = val;
} else {
insert(box, val, i + 1);
}
}
int main(void) {
long long box[10] = {};
long long phone;
while (scanf("%lld,", &phone) != EOF) {
insert(box, phone, 0);
}
for (int i = 0, size = 10; i < size - 1; i++) {
printf("%lld,", box[i]);
}
printf("%lld", box[9]);
return 0;
}