题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
#include <stdio.h> int main() { short n = 0, i = 0, j = 0; short a, b[1000] = {0}, c[1000] = {0}; scanf("%d", &n); for(i = 1; i <= n; i++) { scanf("%d", &a); b[a] = a; //printf("b[%d]=%d\n", a, b[a]); } while (0)//scanf("%d", &a) != EOF) { b[a] = a; //printf("b[%d]=%d\n", a, b[a]); } //printf("n=%d\n", n); for(i = 1; i <= 1000; i++) { if(b[i] == i) { c[j++] = i; //printf("n=%d b[%d]=%d c[%d]=%d\n", n, i, b[i], j-1, c[j-1]); } } for(i = 0; i < j; i++) { printf("%d\n", c[i]); } return 0; }