电子科大POJ "孤单整数"

  孤单整数


Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)




C-sources:
 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     int num,pa,temp,test=0;
 6     printf("Please input the value of num:
");
 7     scanf("%d",&num);
 8 
 9     pa=num/2;
10 
11     int *array=NULL;
12     array=(int*)malloc(num*sizeof(int));
13 
14     printf("Please input the array:
");
15     int i,j,k=0;
16     for(i=0;i<num;i++)
17         scanf("%d",&array[i]);
18 
19     for(i=0;i<num;i++)
20     {
21          temp=array[i];
22          for(j=i+1;j<num;j++)
23          {
24             if(temp==array[j])
25                {
26                  test++;
27 
28                }
29          }
30     }
31 
32     if(test==pa)
33        {
34            int *compa=(int*)malloc(pa*sizeof(int));
35            for(i=0;i<pa;i++)
36             compa[i]=0;
37 
38             for(i=0;i<num;i++)
39                 {
40                     temp=array[i];
41                     for(j=i+1;j<num;j++)
42                     {
43                         if(temp==array[j])
44                         {
45                             compa[k]=temp;
46                             k++;
47                         }
48                     }
49                 }
50 
51 
52         int p=0,mem=0;
53             for(i=0;i<num;i++)
54             {
55                 p=0;
56                 for(j=0;j<pa;j++)
57                 {
58                     if(array[i]==compa[j])
59                         break;
60                     else
61                     {
62                         p++;
63                         mem=i;
64                     }
65                 }
66                 if(p==4)
67                     printf("%d",array[i]);
68             }
69        }
70     return 0;
71 }

 

原文地址:https://www.cnblogs.com/vpoet/p/4659763.html