为啥本地没问题,再洛谷ide就出错了啊~555
  • 板块P1957 口算练习题
  • 楼主oidd
  • 当前回复7
  • 已保存回复7
  • 发布时间2022/11/29 22:33
  • 上次更新2023/10/27 00:57:50
查看原帖
为啥本地没问题,再洛谷ide就出错了啊~555
853487
oidd楼主2022/11/29 22:33
#include <bits/stdc++.h>
using namespace std;
int n;
char bi[100][15];
int main()
{
    cin >> n;   //cin 不读回车
    cin.get();
    for (int i = 0; i < n; ++i)
        cin.getline(bi[i], 15);

    char pre;
    //int num1, num2;
    for (int i = 0; i < n; ++i)
    {
        int num1 = 0, num2 = 0;
        int tol = 0;
        bool flag1 = false;
        int length1 = 0, length2 = 0, length3 = 0;

        if (bi[i][0] >= 'a' && bi[i][0] <= 'c')
        {
            pre = bi[i][0];
            int length = 2;
            while (bi[i][length])
            {
                if (bi[i][length] == ' ')
                {
                    flag1 = true;
                    length++;
                }
                if (!flag1)
                {
                    num1 = num1 * 10 + (bi[i][length] - 48);
                    length1++; length++;
                }
                else
                {
                    num2 = num2 * 10 + (bi[i][length] - 48);
                    length2++; length++;
                }
            }


        }
        else
        {
            int length = 0;
            while (bi[i][length])
            {
                if (bi[i][length] == ' ')
                {
                    flag1 = true;
                    length++;
                }
                if (!flag1)
                {
                    num1 = num1 * 10 + (bi[i][length] - 48);
                    length1++; length++;
                }
                else
                {
                    num2 = num2 * 10 + (bi[i][length] - 48);
                    length2++; length++;
                }
            }
        }

        if (pre == 'a')
        {
            tol = num1 + num2;
            cout << num1 << '+' << num2 << '=' << num1 + num2 << endl;
        }
        else if (pre == 'b')
        {
            tol = num1 - num2;
            cout << num1 << '-' << num2 << '=' << num1 - num2 << endl;
        }
        else
        {
            tol = num1 * num2;
            cout << num1 << '*' << num2 << '=' << num1 * num2 << endl;
        }

        bool flag2 = false;
        if (tol < 0)
            flag2 = true;
        while (tol)
        {
            length3++;
            tol /= 10;
        }
        int ans = length1 + length2 + length3 + 2;
        flag2 ? cout << ans + 1 << endl : cout << ans << endl;

    }
    return 0;
}
2022/11/29 22:33
加载中...