题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
#include <stdio.h>
#include <stdlib.h>
int main() {
int N,n,figure;
scanf("%d",&N);
short *array = (short *)malloc(N * sizeof(short));
for(int i=0;i<N;i++)
{
scanf("%d",&figure);
array[i]=figure;
}
//去重
n=N;
for(int i=0;i<N-1;i++)
{
if((figure = array[i])==0)
continue;
for(int j=i+1;j<N;j++)
{
if(array[j]==figure){
array[j]=0;
n--;
}
}
}
//排序
short *sort = (short*)malloc(n*sizeof(short));
for(int i=0;i<N;i++)
{
if((figure = array[i])==0)
continue;
int index = 0;
for(int j=0;j<N;j++)
{
int figure2;
if((figure2 = array[j])==0)
continue;
if(figure2<figure)
index++;
}
sort[index]=figure;
}
free(array);
for(int i=0;i<n;i++)
{
printf("%d\r\n",sort[i]);
}
free(sort);
return 0;
}