RE了,给我整蒙了

P1307 [NOIP2011 普及组] 数字反转

mrHCT @ 2022-04-12 16:57:58

#include<stdio.h>
#include<math.h>
int main()
{
    int n,b,m;
    int s,o;
    int sun;
    double sum=0,c;
    int a[50];
    int i=0;
    scanf("%d",&n);
    if(n>0)
    {
    while(n!=0)
    {
    a[i]=n%10;
    n=n/10;
    i++;
    m=i;
    o=i;
    s=1;
}}
    else if(n<0)
    {
    n=abs(n);
    while(n!=0)
    {
    a[i]=n%10;
    n=n/10;
    i++;
    s=-1;
    m=i;
    o=i;
}   
    }
    for(int i=0;i<o;i++)
    {
        c=a[i]*pow(10,m-1);
        sum+=c;
        m--;
    }
    sun=(int)sum;
    if(s==-1)
    printf("-%d\n",sun);
    else if(s==1)
    printf("%d",sun);
    else if(n==0)
    {
        printf("0");
    }
    return 0;
}

by KAqwq @ 2022-04-12 17:11:41

检查一下自己数组是不是开小了 一般的RE都是这@mrHCT


by mrHCT @ 2022-04-12 17:15:11

@Kamisato_Ayato


by KAqwq @ 2022-04-12 17:34:36

@mrHCT


by mrHCT @ 2022-04-12 22:25:54

确实是数组开小了


|