70pts求救

P1957 口算练习题

laoqiu_tyxx @ 2024-12-18 17:08:49

rt

#include<bits/stdc++.h>
using namespace std;
int n,i,j,b,c;
char a,a1;
int csandcnt(int mns)
{
    string nm;
    while(mns)
    {
        nm+=mns%10;
        mns/=10;
    }
    return nm.size();
}
char arad(char an)
{
    switch(an)
    {
        case 'a':return '+';break;
        case 'b':return '-';break;
        case 'c':return '*';break;
    }
}
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a1;
        if(a1>='0' && a1<='9')
        {
            cin>>b>>c;
            b=b+pow(10,csandcnt(b))*(a1-'0');
            int ad;
            if(a=='a')
            {
                ad=b+c;
            }
            else if(a=='b')
            {
                ad=b-c;
            }
            else if(a=='c')
            {
                ad=b*c;
            }
            cout<<b<<arad(a)<<c<<"="<<ad<<endl;
            int len=csandcnt(b)+csandcnt(c)+2+csandcnt(ad);
            if(ad<0)
            {
                len++;
            }
            cout<<len<<endl;
        }
        else
        {
            a=a1;
            cin>>b>>c;
            int ad;
            if(a=='a')
            {
                ad=b+c;
            }
            else if(a=='b')
            {
                ad=b-c;
            }
            else if(a=='c')
            {
                ad=b*c;
            }
            cout<<b<<arad(a)<<c<<"="<<ad<<endl;
            int len=csandcnt(b)+csandcnt(c)+2+csandcnt(ad);
            if(ad<0)
            {
                len++;
            }
            cout<<len<<endl;
        }
    }
}

by Sutong123 @ 2024-12-25 18:05:41

需要特判复数。


by Sutong123 @ 2024-12-25 18:06:35

测试: 2 a 1 1 1 1


|