提交时间:2026-01-04 15:12:55
运行 ID: 80330
#include <iostream> using namespace std; int main() { int n; cin >> n; // 特殊情况:如果n是0,但题目说n>=1,所以可以不处理 // 但为了代码健壮性,可以加上 if(n==0) {cout<<0; return 0;} bool firstDigit = true; // 标记是否是第一个输出的数字 while (n > 0) { int digit = n % 10; // 取出个位数字 n /= 10; // 去掉个位 if (!firstDigit) { cout << " "; // 不是第一个数字,先输出空格 } cout << digit; firstDigit = false; // 第一次输出后标记为false } cout << endl; return 0; }