求助

P1957 口算练习题

ymm12138 @ 2023-02-26 17:22:57

#include<iostream>
using namespace std;
int main(){
    int n;
    char state; 
    cin>>n;
    for(int i=0;i<n;i++){
        int n1,n2;
        char a1;
        cin>>a1;
        char a11=a1;
        if(a1!='a'&&a1!='b'&&a1!='c'){
            cin>>n1;
            n1=(a1-48)*100+n1;
            cin>>n2;
        }else{
            state=a1;
            cin>>n1 >>n2;
        }
            if(state=='a'){
            printf("%d+%d=%d\n",n1,n2,(n1+n2));int num=2;int num1=n1+n2;
                do{
                    n1/=10;num++;               
                }while(n1!=0);
                do{
                    n2/=10;num++;               
                }while(n2!=0);
                do{
                    (num1)/=10;num++;               
                }while(num1!=0);
            printf("%d\n",num);
            }
            if(state=='b'){
            printf("%d-%d=%d\n",n1,n2,(n1-n2));int num=2;int num1=n1-n2;
                do{
                    n1/=10;num++;               
                }while(n1!=0);
                do{
                    n2/=10;num++;               
                }while(n2!=0);
                do{
                    (num1)/=10;num++;
                        if(num1<0)num++;                    
                }while(num1!=0);
            printf("%d\n",num);
            }
            if(state=='c'){
            printf("%d*%d=%d\n",n1,n2,(n1*n2));int num=2;long long int num1=n1*n2;
                do{
                    n1/=10;num++;

                }while(n1!=0);
                do{
                    n2/=10;num++;

                }while(n2!=0);
                do{
                    (num1)/=10;num++;

                }while(num1!=0);
            printf("%d\n",num);
            }

    }

    return 0;
}

只过了3个测试点,求大佬帮忙看看问题,感激不尽!


|