0分!求助QAQ!

P1957 口算练习题

good_codeman @ 2021-11-15 22:10:33

求助


by rzh123 @ 2021-11-15 22:13:00

@18956268468ab 你交个文言 A+B 还想过?


by FanSizhe127 @ 2022-05-03 09:52:35

#include<bits/stdc++.h>
using namespace std;
int len(int d){
    int a=d,x=0;
    while(a)
    {
        x++;
        a/=10;
    }
    if(d<=0)
        return x+1;
    else
        return x;
}
int main()
{
    int n,a,b,s;
    cin>>n;
    string q;
    char c,old;
    int i,j,k,l;
    for(i=1;i<=n;i++)
    {
        cin>>q;
        if(q=="a"||q=="b"||q=="c")
        {
            cin>>a>>b;
            if(q=="a")
            {
                cout<<a<<'+'<<b<<'='<<a+b;
                s=a+b;
                old='a';
            }
            if(q=="b")
            {
                cout<<a<<'-'<<b<<'='<<a-b;
                s=a-b;
                old='b';
            }
            if(q=="c")
            {
                cout<<a<<'*'<<b<<'='<<a*b;
                s=a*b;
                old='c';
            }
            cout<<'\n';
            int o=len(a)+len(b)+len(s);
            cout<<o+2<<'\n';
        }
        else
        {
            int u=0;
            for(j=0;j<q.size();j++)
            {
                u=u*10+q[j]-'0';
            } 
            a=u;
            cin>>b;
            if(old=='a')
            {
                cout<<a<<'+'<<b<<'='<<a+b;
                s=a+b;
                old='a';
            }
            if(old=='b')
            {
                cout<<a<<'-'<<b<<'='<<a-b;
                s=a-b;
                old='b';
            }
            if(old=='c')
            {
                cout<<a<<'*'<<b<<'='<<a*b;
                s=a*b;
                old='c';
            }
            cout<<'\n';
            cout<<len(a)+len(b)+len(s)+2<<'\n';
        }
    }
}

|