
1 #include<stdio.h> 2 #include<string.h> 3 int a[510],b[510]; 4 int c[130000]; 5 int main() 6 { 7 int n,i,x,j; 8 while(scanf("%d",&n),n!=0) 9 { 10 memset(c,0,sizeof(c)); 11 for(i=0;i<n;i++) 12 scanf("%d",&a[i]); 13 for(i=0;i<n;i++) 14 { 15 x=a[i]; 16 if(c[x]==0) 17 { 18 while(x!=1) 19 { 20 if(x%2!=0) 21 { 22 x=x*3+1; 23 x=x/2; 24 c[x]=1;//用来标记已经覆盖的数字 25 } 26 else 27 { 28 x=x/2; 29 c[x]=1; 30 } 31 } 32 } 33 } 34 j=0; 35 for(i=0;i<n;i++) 36 { 37 if(c[a[i]]==0)//如果数字没有被覆盖,说明为关键数 38 b[j++]=a[i];//存入b[]中 39 } 40 printf("%d",b[j-1]); 41 for(i=j-2;i>=0;i--) 42 printf(" %d",b[i]); 43 printf("\n"); 44 } 45 return 0; 46 }