题解 | #序列中整数去重# #函数实现#
序列中整数去重
https://www.nowcoder.com/practice/6564a2f6e70f4153ad1ffd58b2b28490
#include <stdio.h> #include<stdlib.h> int re(int *arr1,int n,int *arr2) { int i,j; for(i = 0;i<n;i++) { for(j = i-1;j >=0;j--) { if(*(arr1+i)==*(arr1+j)) *(arr1+i) = -1; } } for(i = 0,j = 0;i<n;i++) { if(*(arr1+i) != -1) { *(arr2+j) = *(arr1+i); j++; } } return j; } int main() { int sum,n,i; scanf("%d",&n); int *arr1 = (int *)malloc(n*sizeof(int)); int *arr2 = (int *)malloc(n*sizeof(int)); for(i=0;i<n;i++) scanf("%d",arr1+i); sum = re(arr1,n,arr2); for(i=0;i<sum;i++) printf("%d ",*(arr2+i)); return 0; }