40分求大佬援助

P1957 口算练习题

jacky5454 @ 2024-09-29 21:35:02

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    char ch;
    int a,b,c,sum=0;
    int n;
    cin>>n;
    while(n--)
    {
        sum=0;
        cin>>ch>>a>>b;
        cout<<a;
        if(ch=='a')
        {
            c=a+b;
            cout<<"+"<<b<<"="<<c<<endl;
        }
        else if(ch=='b')
        {
            c=a-b;
            cout<<"-"<<b<<"="<<c<<endl;
        }
        else
        {
            c=a*b;
            cout<<"*"<<b<<"="<<c<<endl;
        }
        while(a)
        {
            a/=10;
            sum++;
        }
        while(b)
        {
            b/=10;
            sum++;
        }
        if(c<0)
        {
            sum++;
        }
        while(c)
        {
            c/=10;
            sum++;
        }
        sum+=2;
        cout<<sum<<endl;
    }
    return 0;
}

|