本地输出和答案一样,但是全WA
查看原帖
本地输出和答案一样,但是全WA
608187
Hikario楼主2022/8/27 09:46

本地调试过样例,提交后全WA,下载了第一个样例并调试后发现输出和答案一模一样QAQ……求大佬帮忙看看 (๑•̀ㅂ•́)و✧

#include<iostream>
using namespace std;
int get(int &i,string s)
{
    int res=0;
    while(i<s.size()&&s[i]!=' ')res*=10,res+=(s[i]-'0'),i++;
    return res;
}
char get_op(char c)
{
    if(c=='a')return '+';
    if(c=='b')return '-';
    if(c=='c')return '*';
}
int get_val(int a,int b,char op)
{
    if(op=='+')return a+b;
    if(op=='-')return a-b;
    if(op=='*')return a*b;
}
int get_lenth(int n)
{
    int res=0;
    if(n<0)res++;
    while(n)n/=10,res++;
    return res;
}
int main()
{
    int T;
    scanf("%d\n",&T);
    char op;
    while(T--)
    {
        string s;
        getline(cin,s);
        int i=0;
        if('a'<=s[0]&&s[0]<='c')op=get_op(s[0]),i=2;
        int a=get(i,s);
        i++;
        int b=get(i,s);
        int c=get_val(a,b,op);
        printf("%d%c%d=%d\n%d\n",a,op,b,c,get_lenth(a)+get_lenth(b)+get_lenth(c)+2);
    }
}
2022/8/27 09:46
加载中...