标签:
题目描述:删除一个数组内重复的元素,并按照原来的相对顺序输出
#include <stdio.h> int main(int argc, const char * argv[]) { int n,temp; int delete_num = 0; scanf("%d",&n); int a[n]; for (int i = 0; i < n;i++) { scanf("%d",&a[i]); } for (int j = 0; j < n-1-delete_num; j++) { for (int k = j+1; k < n-delete_num; k++) { if (a[j] == a[k]) { delete_num++; for (int p = k; p < n-delete_num; p++) { temp = a[p]; a[p] = a[p+1]; a[p+1] = temp; } k--; } } } for (int m = 0; m < n - delete_num; m++) { printf("%d ",a[m]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liuhao-1997/p/4984093.html