This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
//反转 办法:模10除10
/*
1234 ---> 1234 % 10 = 4
1234 / 10 =123 123 %10 = 3
123 / 10 =12 12 % 10 = 2
12/10= 1 1 % 10 = 1
123040 -> 40321
*/
using namespace std;
int n; //整数变量n
int main() {
//读入变量n
cin >> n; //从键盘读入
// 0 如果是0,那么输出0
if (n == 0)
cout << 0 << endl;
else {
//如果小于0要输出一个负号 -1234 ---> -4321
if (n < 0) {
cout << "-";
n = -n;
}
bool flag = false; //定义成还没有遇到第一个非零数字
while (n) {
if (n % 10 == 0) {
if (flag) cout << 0;
} else {
flag = true;
cout << n % 10;
n /= 10;
return 0;