求助!输出是对的但是0分

P1307 [NOIP2011 普及组] 数字反转

pikasonic @ 2024-12-16 19:57:36

#include <stdio.h>

int reverse(int x);
int main() {
    int x;
    scanf("%d",&x);
    if(x==0)
        printf("0");
    else if(x>0)
        printf("%d",reverse(x));
    else if(x<0)
        printf("-%d",reverse(-x));
    return 0;
}
int reverse(int x){
    int t=x,y;
    while(t>0){
        y+=(t%10);
        y*=10;
        t/=10;
    }
    return y/10;
}

by XURUIFAN @ 2024-12-16 20:06:39

建议y初始化


by Jerry555 @ 2024-12-16 20:10:42

初始化y


|