P1957口算练习题
  • 板块题目总版
  • 楼主panbaokun123
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/11/9 23:31
  • 上次更新2023/10/27 03:34:17
查看原帖
P1957口算练习题
824353
panbaokun123楼主2022/11/9 23:31

我在编译器上是可以通过样例的,但是在这里全部报的错误是RE,这是咋回事,哪里出了问题,大佬指点一下

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

//unordered_map<char,char> mp;

int main()
{
    int n;
    scanf("%d",&n);
	getchar();
    vector<string> opnd;
    for(int i = 0;i < n;i++)
    {
        string s;
        getline(cin,s);
        opnd.push_back(s);
    }
    
    char ch;
    for(int i = 0;i < n;i++)
    {
        if(opnd[i][0] == 'a' || opnd[i][0] == 'b' || opnd[i][0] == 'c')
        {
            ch = opnd[i][0];
            int x,y;
            string str;
            for(int j = 2;j < opnd[i].size();j++)
            {
                if(opnd[i][j] == ' ')
                {
                    x = stoi(str);
                    str = "";
                    continue;
                }
                str += opnd[i][j];
            }
            y = stoi(str);
            if(ch == 'a')
            {
                cout << x << "+" << y << "=" << x+y << endl;
                cout << (int)log10(x)+(int)log10(y)+(int)log10(x+y)+5 << endl;
            }
            else if(ch == 'b'&&x>y)
            {
                cout << x << "-" << y << "=" << x-y << endl;
                cout << (int)log10(x)+(int)log10(y)+(int)log10(x-y)+5 << endl;
            }
			else if(ch == 'b'&&x<y)
			{
				cout << x << "-" << y << "=" << x-y << endl;
				cout << (int)log10(x)+(int)log10(y)+(int)log10(abs(x-y))+5+1 << endl;
			}
            else if(ch == 'c')
            {
                cout << x << "*" << y << "=" << x*y << endl;
                cout << (int)log10(x)+(int)log10(y)+(int)log10(x*y)+5 << endl;
            }
        }
        else
        {
            int x,y;
            string str;
            for(int j = 0;j < opnd[i].size();j++)
            {
                if(opnd[i][j] == ' ')
                {
                    x = stoi(str);
                    str = "";
                    continue;
                }
                str += opnd[i][j];
            }
            y = stoi(str);
            if(ch == 'a')
            {
                cout << x << "+" << y << "=" << x+y << endl;
                cout << (int)log10(x)+(int)log10(y)+(int)log10(x+y)+5 << endl;
            }
            else if(ch == 'b'&&x>y)
            {
                cout << x << "-" << y << "=" << x-y << endl;
                cout << (int)log10(x)+(int)log10(y)+(int)log10(x-y)+5 << endl;
            }
			else if(ch == 'b'&&x<y)
			{
				cout << x << "-" << y << "=" << x-y << endl;
				cout << (int)log10(x)+(int)log10(y)+(int)log10(abs(x-y))+5+1 << endl;
			}
            else if(ch == 'c')
            {
                cout << x << "*" << y << "=" << x*y << endl;
                cout << (int)log10(x)+(int)log10(y)+(int)log10(x*y)+5 << endl;
            }
        }
    }
    //system("pause");
    return 0;
}
2022/11/9 23:31
加载中...