90分#2WA求助dalao

P1957 口算练习题

ComplexPlanck @ 2021-10-02 12:13:10

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

char ch;
ll n,p,a,b;

ll wei(ll x)
{
    if (x==0) return 1;
    ll num=0;
    if (x<0) {num=1;x*=-1;} 
    while (x!=0)
    {
        x=(x-x%10)/10;
        num++;
    }
    return num;
}

int main()
{
    // freopen("CPl.in","r",stdin);
    // freopen("CPl.out","w",stdout);
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>ch>>a>>b;
        if (ch=='a') p=1;
        else if (ch=='b') p=2;
        else if (ch=='c') p=3;
        else a+=int(ch-'0')*pow(10,wei(a));

        if (p==1) printf("%lld+%lld=%lld\n%lld\n",a,b,a+b,wei(a)+wei(b)+wei(a+b)+2);
        else if (p==2) printf("%lld-%lld=%lld\n%lld\n",a,b,a-b,wei(a)+wei(b)+wei(a-b)+2);
        else if (p==3) printf("%lld*%lld=%lld\n%lld\n",a,b,a*b,wei(a)+wei(b)+wei(a*b)+2);
    }
    return 0;
}

by Mr_Iridescent @ 2021-10-12 20:38:27

1074 7558 这一组数据 a+=int(ch-'0')*pow(10,wei(a)); 1074会变成174


|