题解 | #继续xxx定律#
继续xxx定律
https://www.nowcoder.com/practice/9cc1055241c547269f58fa8b009e335d
#include <iostream>
using namespace std;
int a[510];
int n;
void func() {
for (int i = 0; i < n; i++) {
int t = a[i];
while (t != 1) {
if (t % 2 == 0) {
t /= 2;
for (int j = 0; j < n; j++) {
if (a[j] == t) a[j] = 1; //覆盖数置为1
}
}else{
t=3*t+1;
t/=2;
for(int j=0;j<n;j++){
if(a[j]==t) a[j]=1;
}
}
}
}
for(int i=n-1;i>=0;i--){
if(a[i]!=1) cout<<a[i]<<" ";
}
cout<<endl;
}
int main() {
while (cin >> n && n) {
for (int i = 0; i < n; i++) cin >> a[i];
func();
}
return 0;
}
查看7道真题和解析