题解 | #序列中删除指定数字#
序列中删除指定数字
https://www.nowcoder.com/practice/7bbcdd2177a445a9b66da79512b32dd7
#include <stdio.h> int main() { int n, arr[52], i, val, pos[52], cnt = 0, j, sign; scanf("%d", &n); for (i=0; i<n; i++){ scanf("%d", &arr[i]); } scanf("%d", &val); for (i=0; i<n; i++){ if (val == arr[i]){ pos[cnt++] = i; //找到要删除的位置 } } for (i=0; i<n; i++){ sign = 0; for (j=0; j<cnt; j++){ if (i == pos[j]){ sign = 1; } } if (0 == sign){ printf("%d ", arr[i]); } } return 0; }