20分求助

P1957 口算练习题

Ac_Code_cn_com @ 2023-10-29 21:13:53

#include<bits/stdc++.h>
using namespace std;
char s;
long long ikun,a1,a2,a3,l=2;
int main(){
    //freopen("口算练习题.in","r",stdin);
    //freopen("口算练习题.out","w",stdout);
    cin>>ikun;
    for(int i=0;i<ikun;i++){
        l=2;
        cin>>s;
        if(islower(s))cin>>a1>>a2;
        else{
            a1=int(s);
            cin>>a2;
        }
        if(s=='a'){
            a3=a1+a2;
            cout<<a1<<"+"<<a2<<"="<<a1+a2<<endl;
            while(a1){
                l++;
                a1/=10;
            }
            while(a2){
                l++;
                a2/=10;
            }
            while(a3){
                l++;
                a3/=10;
            }
            cout<<l<<endl;
        }
        if(s=='b'){
            a3=a1-a2;
            cout<<a1<<"-"<<a2<<"="<<a1-a2<<endl;
            while(a1){
                l++;
                a1/=10;
            }
            while(a2){
                l++;
                a2/=10;
            }
            while(a3){
                l++;
                a3/=10;
            }
            cout<<l<<endl;
        }
        if(s=='c'){
            a3=a1*a2;
            cout<<a1<<"*"<<a2<<"="<<a1*a2<<endl;;
            while(a1){
                l++;
                a1/=10;
            }
            while(a2){
                l++;
                a2/=10;
            }
            while(a3){
                l++;
                a3/=10;
            }
            cout<<l<<endl;
        }
    }
    return 0;
}

|