80分求助~

P1307 [NOIP2011 普及组] 数字反转

cbt2022110024 @ 2022-11-18 21:40:40

#include <stdio.h>
int main()
{
    int N,a,b=0;
    int A[20];
    A[0]=0;
    scanf("%d",&N);
    if(N<0)
    {
        N=-N;
        printf("-");
    }
    for(int i=1;;i++)
    {
        a=N%10;
        N=N/10;
        if(a!=0||A[b]!=0)
        {
            b++;
            A[b]=a;
        }
        if(N==0)
        {
            break;
        }
    }
    for(int j=1;j<=b;j++)
    {
        printf("%d",A[j]);
    }
    return 0;
}

by zzzzl22 @ 2023-01-18 15:49:46

等于0没有判断


by zzzzl22 @ 2023-01-18 15:52:55

输入1001会输出101


by zzzzl22 @ 2023-01-18 15:54:30

简便的方法:不要搞数组,判断一下直接输出就好


|