Description
In this exercise you need to process a set of data, which has duplicate data and is unsorted. You need to sort them and just print one of the same data.
Input
the first line is a number n(0<n<=50), which stands for the number of test data.
the next 2*n lines contain n group of test data
In each group of test data , the first is a number m(0<m<=50) stands for the size of the test data, and the next line is the test datas.
Output
print sorted data without duplicate data.
Every output item is followed by a space , including the last output item. And each group of output is split by "\n", including the last row.
Sample Input
3
8
5 5 4 4 3 3 2 2
5
-2 -2 -3 -3 0
10
9 4 6 5 7 8 0 1 3 2
Sample Output
2 3 4 5
-3 -2 0
0 1 2 3 4 5 6 7 8 9
Code:
#include<stdio.h>
int main(){
int n,i,j,k,x,temp,record=1,mid;
scanf("%d",&n);
int lim[50],num[50]={0},arr[50][50]={0},dis[50][50]={0};
for(i=0;i<n;i++)
{
scanf("%d",&lim[i]);
for(j=0;j<lim[i];j++){
scanf("%d",&arr[i][j]);
for(k=num[i]-1,record=1;k>=0;k--)
{
if(arr[i][j]==dis[i][k])
{
record=0;
k=-1;
}
}
if(record){
dis[i][num[i]]=arr[i][j];
mid=num[i];
num[i]++;
for(x=num[i]-1;x>=0;x--)
{
if(dis[i][mid]<dis[i][x])
{
temp=dis[i][mid];
dis[i][mid]=dis[i][x];
dis[i][x]=temp;
mid=x;
}
}
}
}
for(j=0;j<num[i];j++)
printf((j==num[i]-1)?"%d \n":"%d ",dis[i][j]);
}
return 0;
}