为什么只有70分啊,我已经抹零了啊

P1307 [NOIP2011 普及组] 数字反转

yuan_666 @ 2024-04-26 10:48:11

#include <iostream>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    if (n == 0)cout << 0;
    for(long long j = n; j!=0;)
    {
        if (j % 10 != 0)
        {
            cout << j % 10;
        }
        else {
            if (j < 0)cout << "-";
        }
        if (j < 0)j = abs(j / 10);
        else j = j / 10;
    }
    return 0;
}

by L_zaa_L @ 2024-04-26 11:39:44

@yuan_666 输入:102 时错了,你把所有的0都弄没了


by yuan_666 @ 2024-04-26 12:21:35

@zaa 感谢提醒


by qusia_MC @ 2024-05-02 14:31:55

@yuan_666


if(j<0)cout<<'-',j*=(-1);
while(j%10==0&&j!=0)j/10;//去除前导0
while(j>0)
{
//你的代码
}

|