全WA,但是自己测试结果都对啊??!!
查看原帖
全WA,但是自己测试结果都对啊??!!
357779
吐了楼主2021/2/27 13:50
#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;
}
2021/2/27 13:50
加载中...