100分,但是第二个任务点#1WA,求dalao指点

P1307 [NOIP2011 普及组] 数字反转

not_exist @ 2022-08-16 16:30:10

#include <bits/stdc++.h>
using namespace std;

int main() {
    long long n, c;
    cin >> n;
    if (n < 0) {
        cout << "-";
        n = abs(n);
    }
    bool x = true;
    while (n != 0) {
        c = n % 10;
        if (c == 0 && x) {
            n /= 10;
        } else {
            cout << c;
            n /= 10;
            x = false;
        }
    }
    return 0;
}

by ajahjahah @ 2022-08-16 16:32:01

@300396ye 输入0不会输出,可以特判一下


by not_exist @ 2022-08-16 16:47:02

@ajahjahah 解决了,谢谢


|