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

34 lines
823 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>
using namespace std;
int n;
int main() {
cin >> n;
//特判
if (n == 0) {
printf("0");
exit(0);
}
//如果是负数,输出负号
if (n < 0) n = -n, printf("-");
//数位分离
bool flag = false;//是否出现过非零数字
//示例: 800 --->8
//示例2 8001 --->1008
//示例3108001 --->100801
while (n) {
int a = n % 10;
n /= 10;
//出现过非0数字
// a==0 && !flag
// a==0 && flag
// a!=0 && !flag
// a!=0 && flag
if (a == 0 && !flag) continue;
else if (a == 0 && flag) cout << a;
else if (a != 0 && !flag) cout << a, flag = true;
else if (a != 0 && flag) cout << a;
}
return 0;
}