注意数组大小(段错误)
#include <stdio.h>
int main() {
int nums[10001], cnt, no;
for (int k = 0; k < 10001; ++k) {
nums[k] = -1;
}
scanf("%d", &cnt);
for (int i = 1; i <= cnt; ++i) {
scanf("%d", &no);
if (nums[no] == -1)
nums[no] = i;
else nums[no] = 0;
}
int first = 0;
nums[0] = cnt + 1;
for (int j = 1; j < 10001; ++j) {
if (nums[j] > 0 && nums[first] > nums[j])
first = j;
}
if (first == 0)
puts("None");
else printf("%d\n", first);
return 0;
}
网友评论