1 条题解
-
0
练13.3 反向输出一个三位数
解题思路
用字符串读入三位数,反转字符顺序后输出。
正确性说明
字符串反转将百、十、个位按相反顺序显示,保留所有三位字符。
易错点
100 应输出 001,本题不能转回整数去掉前导零。
复杂度
本题输入规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; reverse(s.begin(), s.end()); cout << s << "\n"; return 0; }
- 1