为什么没输出?

P1957 口算练习题

MuYuMC @ 2024-05-31 20:53:12

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
int book[11000];
int len(int x)
{
    int len = 0;
    while(x != 0)
    {
        len++;
        x /= 10;
    }
    return len;
}
int main()
{
    string s;
    char opt;
    int a,b,n,i;
    cin >> n;
    while(n--)
    {
        cin >> s;
        if(s[0] == 'a' || s[0] == 'b' || s[0] == 'c')
        {
            opt == s[0];
            cin >> a;
        }
        else
        {
            a = 0;
            for(i = 0;i < s.size();i++)
            {
                a = a * 10 + (s[i] - '0');
             } 
        } 
        cin >> b;
        if(opt == 'a')
        {
            cout << a << "+" << b << "=" << a + b << endl;
            cout << len(a) + len(b) + len(a + b) + 2 << endl;
        }
        if(opt == 'b')
        {
            cout << a << "-" << b << "=" << a - b << endl;
            cout << len(a) + len(b) + len(a - b) + 2 << endl;
        }
        if(opt == 'c')
        {
            cout << a << "*" << b << "=" << a * b << endl;
            cout << len(a) + len(b) + len(a * b) + 2 << endl;
        }
    }
    return 0;
}

by MuYuMC @ 2024-05-31 21:07:13

已找到错误

opt = s[0] 写成 opt == s[0]了

|