求助,#2WA了

P1957 口算练习题

Vivi1206 @ 2024-01-09 21:07:38

#include <bits/stdc++.h>
using namespace std;
int sanpai(int a){
    int sum = 0;
    if(a == 0) return 1;
    if(a < 0) sum++;
    while(a){
        a /= 10;
        sum++;
    }
    return sum;
}
int main(){
    int n;
    char arcaea;
    cin >> n;
    while(n--){
        int x, y, ans = 0;
        char c;
        cin >> c >> x >> y;
        if(c >= '0' && c <= '9'){
            x += (c - '0') * pow(10, sanpai(x));
            if(arcaea == '+'){
                ans = x + y;
            }else if(arcaea == '-'){
                ans = x - y;
            }else if(arcaea == '*'){
                ans = x * y;
            }
        }else{
            if(c == 'a'){
                arcaea = '+';
                ans = x + y;
            }else if(c == 'b'){
                arcaea = '-';
                ans = x - y;
            }else if(c == 'c'){
                arcaea = '*';
                ans = x * y;
            }
        }
        cout << x << arcaea << y << "=" << ans << "\n";
        int sum = 2;
        sum += sanpai(x) + sanpai(y) + sanpai(ans);
        cout << sum << "\n";
    }
    return 0;
}

by Vivi1206 @ 2024-01-09 21:14:13

找到了,8045读成845了(


by Vivi1206 @ 2024-01-09 21:34:44

过了,还是用了string((


|