题解 | #KiKi去重整数并排序#
KiKi去重整数并排序
http://www.nowcoder.com/practice/f59b914172b94c69a2b29ad0a1d9b1a7
#include <stdio.h>
int main()
{
int n, i;
scanf("%d", &n);
int arr[1001] = {0}; //数组大小设为1001,而不是1000,反正也不差这一个
int temp =0;
for(i=0; i<n; i++)
{
scanf("%d ", &temp); //依次输入
if(temp >= 1 && temp <= 1000)
arr[temp] = temp; //将输入的值赋值到下标相同的数组中去
}
for(i=0; i<=1000; i++)
if(arr[i] != 0) //出现过的值,数组中的0会变为相应的值,没出现的仍为0
printf("%d ", arr[i]); //只打印出现过的值,不重复的
return 0;
}