求助

P1957 口算练习题

dino @ 2021-08-17 11:18:03

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

int len;
int ans;
string a; 
int b, c, t;
void wmake(char sign)
{
    len = 2;
    cout << b << sign << c << '=' << ans << endl;
    while(b)
    {
        b /= 10;
        len++;
    }
    while(c)
    {
        c /= 10;
        len++;
    }
    if(ans < 0) len++; 
    while(ans)
    {
        ans /= 10;
        len++;
    }
    cout << len << endl;
}
int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        cin >> a;
        if(a[0] >= 'a' && a[0] <= 'c')
        {   
            t = a[0] - 'a';
            cin >> b >> c;
        } 
        else
        {
            for(int i = 0; i < a.size(); i++)
            {
                b = b * 10 + (a[i] - '0');
            }
            cin >> c;
        }
        if(t == 0)
        {
            ans = b + c;
            wmake('+');
        }
        else if(t == 1)
        {
            ans = b - c;
            wmake('-');
        }
        else
        {
            ans = b * c;
            wmake('*');
        }
    }
 } 

80分,样例过了


by Zxc200611 @ 2021-08-17 11:31:19

Hack:

Input:
1
a 0 0
Answer:
0+0=0
5

by dino @ 2021-08-17 11:56:03

@Zxc200611 谢啦


|