#include<iostream>
#include<string>
using namespace std;
int reverse1(int x) { //循环迭代
int y = 0;
while (x) {
y = y * 10 + x % 10;
x /= 10;
}
return y;
}
int reverse2(int x, int y = 0) { //递归版
return x == 0 ? y : reverse2(x / 10, y * 10 + x % 10);
}
string reverse3(string x) { //当成字符串使用反向迭代器构造新字符串
return string(x.rbegin(), x.rend());
//return x.assign(x.rbegin(), x.rend());
}
int main() {
cout << reverse1(123) << endl;
cout << reverse2(123) << endl;
cout << reverse3(to_string(123)) << endl;
return 0;
}