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.

35 lines
664 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N], idx;
// 1234000
int main() {
int n;
cin >> n;
if (n == 0) {
cout << 0 << endl;
exit(0);
}
if (n < 0) {
cout << "-";
n = -n;
}
while (n) {
a[++idx] = n % 10; //由后到前 4 3 2 1 --> a[1]=4 a[2]=3
n /= 10;
}
bool flag = false; //是不是已经遇到过一个非零数字
for (int i = 1; i <= idx; i++) {
if (a[i] != 0) flag = true;
if (a[i] == 0) {
if (flag) cout << 0;
} else
cout << a[i];
}
return 0;
}