为什么就对了60%,测试数据也是对的

P1957 口算练习题

ws778 @ 2024-12-19 21:12:48

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int n;
    char ch[100][100000];
    scanf("%d",&n);
    getchar();
    int i=0;
    while(n--)
    {
        gets(ch[i]);
        int a=0,b=0;
        if(ch[i][0]=='a')
        {
            sscanf(ch[i],"a %d %d",&a,&b);
            int sum=a+b;
            if(sum==0)
            {
                int len=3;
                printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }
            if(sum!=0&&b==0&&a!=0)
            {
                int len=log10(sum)+(int)log10(a)+3;
                printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }
            if(sum!=0&&b!=0&&a==0)
            {
                int len=log10(sum)+(int)log10(b)+3;
                printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }
            else
            {
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
            printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }
        }
    if(ch[i][0]=='b')
        {
            sscanf(ch[i],"b %d %d",&a,&b);
            int sum=a-b;
            if(sum==0&&a==0&&b==0)
            {
                int len=3;
                printf("%d-%d=%d\n%d",a,b,sum,len+2);   
            }
            else if(sum==0&&a!=0&&b!=0)
            {
                int len=(int)log10(a)+(int)log10(b)+3;
                printf("%d-%d=%d\n%d",a,b,sum,len+2);
            }
            else if(sum<0)
            {
                sum=fabs(sum);
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
                printf("%d-%d=-%d\n%d",a,b,sum,len+3);
            }
            else
            {
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
                printf("%d-%d=%d\n%d",a,b,sum,len+2);
            }
        } 
    if(ch[i][0]=='c')
        {
            sscanf(ch[i],"c %d %d",&a,&b);
            int sum=a*b;
            if(sum==0&&a==0&&b==0)
            {
                int len=3;
                printf("%d*%d=%d\n%d",a,b,sum,len+2);   
            }
            else if(sum==0&&a==0&&b!=0)
            {
                int len=(int)log10(b)+3;
                printf("%d*%d=%d\n%d",a,b,sum,len+2);   
            }
            else if(sum==0&&a!=0&&b==0)
            {
                int len=(int)log10(a)+3;
                printf("%d*%d=%d\n%d",a,b,sum,len+2);   
            }
            else
            {
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
            printf("%d*%d=%d\n%d",a,b,sum,len+2);
                }   
        }   
     if(ch[i][0]!='c'&&ch[i][0]!='a'&&ch[i][0]!='b'&&ch[i-1][0]=='b')
        {
            sscanf(ch[i],"%d %d",&a,&b);
            int sum=a-b;
            if(sum==0&&a==0&&b==0)
            {
                int len=3;
                printf("%d-%d=%d\n%d",a,b,sum,len+2);   
            }
            else if(sum==0&&a!=0&&b!=0)
            {
                int len=(int)log10(a)+(int)log10(b)+3;
                printf("%d-%d=%d\n%d",a,b,sum,len+2);
            }
            else if(sum<0)
            {
                sum=fabs(sum);
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
                printf("%d-%d=-%d\n%d",a,b,sum,len+3);
            }
            else
            {
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
                printf("%d-%d=%d\n%d",a,b,sum,len+2);
            }
        } 
    if(ch[i][0]!='c'&&ch[i][0]!='a'&&ch[i][0]!='b'&&ch[i-1][0]=='a')
        {
                sscanf(ch[i],"%d %d",&a,&b);
            int sum=a+b;
            if(sum==0)
            {
                int len=3;
                printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }
            if(sum!=0&&b==0&&a!=0)
            {
                int len=log10(sum)+(int)log10(a)+3;
                printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }
            if(sum!=0&&b!=0&&a==0)
            {
                int len=log10(sum)+(int)log10(b)+3;
                printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }
            else
            {
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
            printf("%d+%d=%d\n%d",a,b,sum,len+2);   
            }   
        }
    if(ch[i][0]!='c'&&ch[i][0]!='a'&&ch[i][0]!='b'&&ch[i-1][0]=='c')
        {
            sscanf(ch[i],"%d %d",&a,&b);
            int sum=a*b;
            if(sum==0&&a==0&&b==0)
            {
                int len=3;
                printf("%d*%d=%d\n%d",a,b,sum,len+2);   
            }
            else if(sum==0&&a==0&&b!=0)
            {
                int len=(int)log10(b)+3;
                printf("%d*%d=%d\n%d",a,b,sum,len+2);   
            }
            else if(sum==0&&a!=0&&b==0)
            {
                int len=(int)log10(a)+3;
                printf("%d*%d=%d\n%d",a,b,sum,len+2);   
            }
            else
            {
                int len=log10(sum)+(int)log10(b)+(int)log10(a)+3;
                printf("%d*%d=%d\n%d",a,b,sum,len+2);
                }   
        } 
    i++;

    printf("\n");
     } 

}

|