求助啊,最后一个WA

P1307 [NOIP2011 普及组] 数字反转

azaz_plus @ 2022-10-17 11:50:21

求助啊

#include<stdio.h>
int main()
{
    int n = 0;
    scanf("%d", &n);
    int k = 0;
    int num = 0;
    if (n > 0)
    {
        while (n > 0)
        {
            k = n % 10;
            n = n / 10;
            num = num * 10 + k;
        }
        printf("%d", num);
    }
    if (n < 0)
    {
        n = n * -1;
        while (n > 0)
        {
            k = n % 10;
            n = n / 10;
            num = num * 10 + k;
        }
        printf("%d", -num);
    }
    return 0;
}

by pengzihao @ 2022-10-17 12:32:13

加个n=0的特判


by azaz_plus @ 2022-10-17 18:01:17

@pengzihao 谢谢大佬


|