全WA,但是自己测试结果都对啊??!!

P1957 口算练习题

吐了 @ 2021-02-27 13:50:49

#include<iostream>
#include<algorithm>
#include<sstream>  
using namespace std;
void f(char x,string s){
    int t=0,j,m=s.length();
    for(j=0;j<m;++j){
        if(s[j]!=' ') ++t;
        else break;
    }

    string s1=s.substr(0,t);   
    int a=atoi(s1.c_str());     
    string s2=s.substr(j+1,m-j-1);  
    int b=atoi(s2.c_str());

    if(x=='a'){
        int c=a+b;
        stringstream cs;     
        cs<<c;              
        string s3=cs.str(); 
        string result=s1+"+"+s2+"="+s3;
        cout<<result<<endl;
        cout<<result.length()<<endl;
    }
    else if(x=='b'){
        int c=a-b;
        stringstream cs; 
        cs<<c;              
        string s3=cs.str();
        string result=s1+"-"+s2+"="+s3;
        cout<<result<<endl;
        cout<<result.length()<<endl;
    }
    else{
        int c=a*b;
        stringstream cs;   
        cs<<c;             
        string s3=cs.str(); 
        string result=s1+"*"+s2+"="+s3;
        cout<<result<<endl;
        cout<<result.length()<<endl;
    }        

} 
int main(){
    int i,n;
    char x;
    cin>>n;
    for(i=0;i<n;++i){

        string s,d;
        cin>>d;
        cin.get();
        getline(cin,s);

        if(d[0]=='a'){
            x='a';
            f(x,s);
        }
        else if(d[0]=='b'){
            x='b';
            f(x,s);
        }
        else if(d[0]=='c'){
            x='c';
            f(x,s);
        }
        else{
            string v=d+" "+s;
            f(x,v);
        }
    }
    return 0;
}

by Nanfeng1997 @ 2021-02-27 21:43:11

我也是全wa 我还把最后一组数据少输入一个回车


上一页 |