求助

P1957 口算练习题

wumingwei @ 2023-02-16 12:43:18

样例对了,数据下载也对了,就是过不了=_=,放洛谷说是输出0

#include<bits/stdc++.h>
using namespace std;
int zt/* 1+2-3* */,l,zt1,x,y,q,z,ll;//zt1 0为前 1为后 
int cd(int w)
{
    int cs=0;
    if(w<0)
    cs++;
    while(w!=0)
    {
        w/=10;
        cs++;
    }
    return cs;
}
int main()
{
//  freopen("1.txt","r",stdin);
//  freopen("2.txt","w",stdout);
    int n;string a;
    cin>>n;
    getchar();
    for(int i=0;i<n;i++)
    {
        a="";
        getline(cin,a);
        q=0;
        l=a.size();
        zt1=0;
        x=0;
        y=0;
        for(int o=0;o<l;o++)
        {
            if(a[o]=='a')
            {
                q+=2;
                zt=1;
                o++;
                continue;
            }
            else if(a[o]=='b')
            {
                q+=2;
                zt=2;
                o++;
                continue;
            }
            else if(a[o]=='c')
            {
                q+=2;
                zt=3;
                o++;
                continue;
            }
            if(a[o]==' ')
            {
                zt1=1;
                continue;
            }
            if(zt1==0)
            {
                x*=10;
                x+=a[o]-'0';
            }

            if(zt1==1)
            {
                y*=10;
                y+=a[o]-'0';
            }

        }
        cout<<x;
        if(zt==1)
        {
            cout<<'+';
            z=x+y;
            ll=cd(z); 
        }
        else if(zt==2)
        {
            z=x-y;
            cout<<'-';
            ll=cd(z);
        }
        else
        {
            z=x*y;
            cout<<'*';
            ll=cd(z);
        }
        cout<<y;
        cout<<'='<<z<<endl<<l-q+ll+1<<endl;
    }
}

by alexander35 @ 2023-02-16 13:50:20

......

一样


|