From d5aba6e9f984382fc1b94cb8e5f324b32a6bc56d Mon Sep 17 00:00:00 2001 From: leo12025 Date: Mon, 4 Aug 2025 11:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=B0=B7=E7=8C=9C=E6=83=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test01/main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test01/main.cpp b/test01/main.cpp index 6e73397..a7cd33d 100644 --- a/test01/main.cpp +++ b/test01/main.cpp @@ -1,20 +1,22 @@ #include "iostream" using namespace std; -int n, r, s = 0, t = 1; +int n; int main() { cin >> n; - while (n > 0) { - r = n % 10; // 将原数的最后一位取出 - n = n / 10; - if (r == 0) { - continue; - } else { - s += r * t; // 将 尾数r 乘上 位权 加到 新数s里 - t *= 10; // 下一次的数字在更高一位 + if (n != 1) { + while (n > 1) { + if (n % 2 == 0) { + n = n / 2; + } else { + n = n * 3 + 1; + } + cout << n << " "; } + cout << endl << "END"; + } else { + cout << "END"; } - cout << s << endl; return 0; }