题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
int main() {
int a[1000], b[1000], len = 1; int i, j, N, k, m = 0, n,temp; scanf("%d", &N); for (i = 0; i < N; i++) { scanf("%d",&a[i]); } b[0] = a[0]; for (j = 1; j < N; j++) { for (k = 0; k < len; k++) { if (b[k] == a[j]) { m++; break; } } if (m == 0) { b[len] = a[j]; len++; } m = 0; } for (i = 0; i < len-1; i++) { for (j = 0; j < len - i-1; j++) { if (b[j] > b[j + 1]) { temp = b[j]; b[j] = b[j + 1]; b[j + 1] = temp; } } } for (n = 0; n < len; n++) { printf("%d\n", b[n]); } return 0;
}