去重排序,这种嵌套的方法非常棒。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4  
 5 int test_student(int *a,int n)
 6 {
 7     int t[1024]={0};
 8     int i;
 9     for (i=0;i<n;i++){
10         t[a[i]] = 1;
11     }
12     for (i=0;i<1024;i++){
13         if(t[i])
14         printf("%d
",i);
15     }
16     return 0;
17  
18 }
19  
20 int main(int argc, char const *argv[])
21 {
22     int i,n;
23     while(~scanf("%d",&n)&&n>0){
24  
25         int *a=malloc(sizeof(int) * n);
26         for(i=0;i<n;i++){
27             scanf("%d",&a[i]);
28         }
29         test_student(a,n);
30         free(a);
31     }
32     return 0;
33 }
View Code
原文地址:https://www.cnblogs.com/zhouyuqing1024/p/11820150.html