60,后4个wa

P1957 口算练习题

WarEpic @ 2024-10-13 15:42:05


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int get_char(int a, int b, int c){
    int index1=0;
    index1=a==0?1:(int)log10(a)+1;
    int index2=0;
    index2=b==0?1:(int)log10(b)+1;
    int index3=0;
    index3=c==0?1:(int)log10(abs(c))+1;
    if(c<0) index3++;
    return index1+index2+index3+2;
}

int main()
{   int n;
    scanf("%d",&n);
    char c[n];
    for(int i=0;i<n;i++) c[i]='0';
    int a[n],b[n];
    for(int i=0;i<n;i++) a[i]=b[i]=0;
    for(int i=0;i<n;i++){
        int result=scanf(" %c %d %d",&c[i],&a[i],&b[i]);
        if(result==2) c[i]='0';
    }

    for(int i=1;i<n;i++){
        if(c[i]!='a' && c[i]!='b' && c[i]!='c') c[i]=c[i-1];
    }

    for(int i=0;i<n;i++){
        if(c[i]=='a'){
            printf("%d+%d=%d\n",a[i],b[i],a[i]+b[i]);
            printf("%d\n",get_char(a[i],b[i],a[i]+b[i]));
        }
        else if(c[i]=='b'){
            printf("%d-%d=%d\n",a[i],b[i],a[i]-b[i]);
            printf("%d\n",get_char(a[i],b[i],a[i]-b[i]));
        }
        else if(c[i]=='c'){
            printf("%d*%d=%d\n",a[i],b[i],a[i]*b[i]);
            printf("%d\n",get_char(a[i],b[i],a[i]*b[i]));
        }
    }
    return 0;
}
```c

by WarEpic @ 2024-10-13 15:43:45

本地第七个测试点能过


|