题解 | #序列中整数去重#
序列中整数去重
https://www.nowcoder.com/practice/6564a2f6e70f4153ad1ffd58b2b28490
#include <stdio.h> int main() { int n = 0; scanf("%d", &n); int arr1[1000]; int arr2[1000]; int i = 0; for (i = 0; i < n; i++) { scanf("%d ", &arr1[i]); } for (i = 0; i < n; i++) { if(i==n-1) { arr2[i]=arr1[i]; } int flag = 0; int j = 0; for (j = i + 1; j < n; j++) { if (arr1[i] != arr1[j]) { flag = 1; } else { arr1[j]=0; } } if (flag == 1) { arr2[i] = arr1[i]; } } for (i = 0; i < n; i++) { if(arr2[i]!=0) { printf("%d ", arr2[i]); } } return 0; }