【发布时间】:2019-06-17 13:33:28
【问题描述】:
从排序数组中删除重复项
#include <stdio.h>
#include <stdlib.h>
int main() {
int arr[12] = { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5 };
int temp[12];
int i, j, k, n = 12;
for (i = 0; i < n - 1; i++) {
if (arr[i] != arr[i + 1]) {
temp[j] = arr[i];
j++;
}
}
temp[j] = arr[n - 1];
for (k = 0; k <= j; k++) {
printf("%d\n", temp[k]);
}
return 0;
}
输出:
6356652
1955753237
1956070172
6356716
1955750536
8
1955687363
1955687354
1
2
3
4
5
Process returned 0 (0x0) execution time : 0.014 s
Press any key to continue.
我不想打印这些数字:
6356652
1955753237
1956070172
6356716
1955750536
8
1955687363
1955687354
【问题讨论】:
-
你没有初始化
j或temp[12]
标签: c arrays algorithm sorting unique