题解:B4301 [蓝桥杯青少年组省赛 2024] 数字交换
题目简述
给定数字
主要思路
用数字交换 string 来读入,这样用一个 swap 就可以完成交换。
对于去除前导
AC Code
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
string n; cin >> n;
// ----------------------------
swap(n[0], n.back());
reverse(n.begin(), n.end());
while (n.back() == '0') n.pop_back();
reverse(n.begin(), n.end());
// ----------------------------
cout << n;
return 0;
}