数字反转
去掉小数点整体反转再补回小数点
正文
// 原题:https://oj.yecheng.tv/p/1347
// 题意:输入 100~1000 且带一位小数的浮点数,把数字整体翻转(如 123.4->4.321)。
// 思路:读成字符串,去掉小数点得到数字串,整体反转,再在第一个数字后加小数点输出。
// 复杂度:O(1)。
// 易错点:是整个数字串反转,不是只反转整数部分;用字符串避免浮点误差。
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string s;
cin >> s;
string t;
for (char c : s) if (c != '.') t += c;
reverse(t.begin(), t.end());
cout << t[0] << "." << t.substr(1) << endl;
return 0;
}