求助大佬,不知为何错了

P1957 口算练习题

HEXIONG520 @ 2023-03-21 22:50:46

#include<stdio.h>
#include<string.h>
int main(){
    int n;
    scanf("%d",&n);
    char a[60][50];
    int i,j,k;
    getchar();
    for(i=0;i<n;i++){
        gets(a[i]);
        if(a[i][0]>='0'&&a[i][0]<='9'){
            for(j=0;a[i][j]!=0;j++){
        }
        for(;j>=0;j--){
            a[i][j+2]=a[i][j];
        }
        a[i][0]=a[i-1][0];
        a[i][1]=' ';
        }
    }

    int s1,s2;
    for(i=0;i<n;i++){
        int space=0;
        for(j=0,s1=0,s2=0;a[i][j]!=0;j++){
            if(a[i][j]==' '){
                space++;
                continue;
            }

            if(a[i][j]>='0'&&a[i][j]<='9'&&space<=1){
                s1=(s1*10+a[i][j]-'0');
            }
               if(a[i][j]>='0'&&a[i][j]<='9'&&space>1){
                s2=s2*10+a[i][j]-'0';
            }

        }

            if(a[i][0]=='a'){
                int sum=s1+s2;
                int wei=0;
                while(sum>0){
                    wei++;
                    sum/=10;
                }
                printf("%d+%d=%d\n",s1,s2,s1+s2);
                printf("%d\n",j-1+wei);
            }
            if(a[i][0]=='c'){
                int sum=s1*s2;
                int wei=0;
                while(sum>0){
                    wei++;
                    sum/=10;
                }
                printf("%d*%d=%d\n",s1,s2,s1*s2);
                printf("%d\n",j-1+wei);
            }
            if(a[i][0]=='b'){
                int sum=s1-s2;
                int wei=0;
                if(sum<0) wei++;
                while(sum!=0){
                    wei++;
                    sum/=10;
                }
                printf("%d-%d=%d\n",s1,s2,s1-s2);
                printf("%d\n",j-1+wei);
            }
    }
    return 0;
} 

by The_Administrator @ 2023-03-22 15:22:05

@HEXIONG520 数据给我


by HEXIONG520 @ 2023-03-22 19:31:10

@ljhwm 啥数据?


by The_Administrator @ 2023-03-24 14:36:21

@HEXIONG520 测试数据和题目


|