题解 | #xxx定律#
xxx定律
https://www.nowcoder.com/practice/75c189249d6145cfa33cd53edae6afc8
#include<iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == 0) {
break;
}
int count = 0;
while (n != 1) {
if (n % 2) {
n = (3 * n + 1) / 2;
} else {
n = n / 2;
}
count++;
}
printf("%d\n", count);
}
}
嵌套了多层while,只要不搞错,此题不难
查看5道真题和解析
正浩创新EcoFlow公司福利 510人发布