为啥全RE了?有大佬能浇浇吗?

P1957 口算练习题

SakuraJG @ 2023-03-02 10:47:37

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std ;
int main()
{
    int n ;
    char condition ;            //记录判断进行运算 
    scanf("%d",&n);
    getchar();
    string space = " ";
    for(int i = 0 ; i < n ; i++)
    {
        int changdu = 0 ;       //最终结果长度 
        string word ;           //输入的字符串 
        getline(cin,word);
        if(word[0] >='a' && word[0] <='c' )
        {
            condition = word[0] ;
            word.erase(0,2);
        }                                   //去掉英文符号 
        changdu = word.length() + 1;    //把含等号左边的长度先算一下 
        int a = 0 , b = 0 ;     //a为第一个数字,b为第二个 
        int index = word.find(space);           //寻找中间的空格下标 
        string abc = word.substr(0,index);      //截取字符串数字a 
        a = atoi(abc.c_str());
        if(a < 0 )              //负数长度就+1 
        {
            changdu++;
        }
        abc = word.substr(index,word.length());     //截取字符串数字b 
        b = atoi(abc.c_str());
        if(b < 0)               //负数长度就+1 
        {
            changdu++;
        }
        int sum = 0 ;
    //  printf("%c %d %d",condition,a,b); 
        switch(condition)               //依据字母来判断运算 
        {
            case 'a' :sum=a+b;printf("%d+%d=%d",a,b,sum);break;
            case 'b' :sum=a-b;printf("%d-%d=%d",a,b,sum);break;
            case 'c' :sum=a*b;printf("%d*%d=%d",a,b,sum);break;
        }
        if(sum < 0)changdu++;
        while(sum != 0)         //求等号位数 
        {
            sum /= 10 ;
            changdu++;
        }
        printf("\n%d\n",changdu);
    }
}

|