Files
python/TangDou/LuoGuBook/P1307_Study.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

37 lines
871 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}