You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
871 B

2 years ago
#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;
}