#include<stdio.h>
int hash[1001];
int a[501];
int main()
{
int n;
while(scanf("%d",&n) != EOF && n != 0){
for(int i = 0;i <= 1000;i++) hash[i] = 1;
hash[0] = hash[1] = 0;
for(int i = 0;i < n;i++){
scanf("%d",&a[i]);
if(hash[a[i]] == 0) continue;
int tmp = a[i];
while(tmp != 1){ //如果输入0 一直除
if(tmp % 2 == 0){
tmp /= 2;
}else{
tmp = (tmp*3+1)/2;
}
if(tmp <= 1000) hash[tmp] = 0;
}
}
bool isfirst = false;
for(int i = n - 1;i >= 0;i--){
if(hash[a[i]] == 1){
if(isfirst == false){
printf("%d",a[i]);
isfirst = true;
}
else printf(" %d",a[i]);
}
}
printf("\n");
}
return 0;
}
/**************************************************************
Problem: 1033
User: cust123
Language: C++
Result: Accepted
Time:10 ms
Memory:1028 kb
****************************************************************/
题目1033:继续xxx定律
最新推荐文章于 2022-09-19 22:32:43 发布