| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 80330 | sh25_huangse | 分离整数的各个数 | C++ | 通过 | 0 MS | 240 KB | 679 | 2026-01-04 15:12:55 |
#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; }