WA30分,测试数据本地能过

P1957 口算练习题

Yancy0423 @ 2024-07-21 21:18:47

#include<bits/stdc++.h>
using namespace std;
int n;
int ax,bx;
char way;
char vec;
int numc;
std::string x;
int num(int a){
    int b=0;
    while(a!=0){
        a/=10;
        b++;
    }
    return b;
}
int turn (string a){
    int ans=0;
    int x=a.length();
    int cnt=1;
    for (int i=x-1;i>=0;i--){
        ans+=(a[i]-'0')*cnt;
        cnt*=10;
    }
    return ans;
}
string a;
string b;
void cut(string x){
    int cd=x.length();
    for(int i=0;i<cd;i++){
        if(x[i]>='0'&&x[i]<='9'){
            a+=x[i];
        }
        if(x[i]==' '&&x[i-1]>='0'&&x[i-1]<='9'){
            for(int j=i+1;j<cd;j++) b+=x[j];
            break;
        }
    }
}

int main(){
    cin>>n;
    for(int i=0;i<=n;i++){
        std::getline(std::cin,x);
        a="";
        b="";
        cut(x);
        ax=turn(a);
        bx=turn(b);
        int numa=num(ax);
        int numb=num(bx);
        if(x[0]=='a'||x[0]=='b'||x[0]=='c'){
        if(x[0]=='a'){
            cout<<a<<"+"<<b<<"="<<ax+bx<<endl;
            numc=num(ax+bx);
            cout<<numa+numb+numc+2<<endl;
        }
        if(x[0]=='b'){
            cout<<a<<"-"<<b<<"="<<ax-bx<<endl;
            if(ax>bx) cout<<num(ax)+num(bx)+num(ax-bx)+2;
            else cout<<num(ax)+num(bx)+num(abs(ax-bx))+3;
        }
        if(x[0]=='c'){
            cout<<a<<"*"<<b<<"="<<ax*bx<<endl;
            cout<<num(ax)+num(bx)+num(ax*bx)+2<<endl;
        }
        vec=x[0];
            }
        else {
        if(vec=='a'){
            cout<<a<<"+"<<b<<"="<<ax+bx<<endl;
            cout<<num(ax)+num(bx)+num(ax+bx)+2<<endl;
        }
        if(vec=='b'){
            cout<<a<<"-"<<b<<"="<<ax-bx<<endl;
            if(ax>bx) cout<<num(ax)+num(bx)+num(ax-bx)+2;
            else cout<<num(ax)+num(bx)+num(abs(ax-bx))+3;
        }
        if(vec=='c'){
            cout<<a<<"*"<<b<<"="<<ax*bx<<endl;
            cout<<num(ax)+num(bx)+num(ax*bx)+2<<endl;
        }
        }
    }
    return 0; 
} 

WA3,4,5,6,8,9,10


|