本地通过但测评机RE
查看原帖
本地通过但测评机RE
137550
laozhang楼主2023/10/20 22:32

本地编译通过了但是使用洛谷的C++11过不了,求大神帮忙

#include<bits/stdc++.h>
#include<sstream>
using namespace std;
int calc(int a,int b,char method);
char show(char x);
int main(){
	int i;
	cin>>i;
	char flag;
	vector<string> results;
	string rr="";
	for(int j=0;j<i;j++){
		char str[500]={0};
		fflush(stdin);
		gets(str);
		if(str[0]=='a'||str[0]=='b'||str[0]=='c'){
			flag=str[0]; 
			istringstream ss(str);
			vector<string> words;
			string word;
			while(ss >> word) {
				words.push_back(word);
			}			
			int a=stoi(words[1]);
			int b=stoi(words[2]);
			int r=calc(a,b,flag);
			//cout<<a<<show(flag)<<b<<"="<<r;
			
			string temp;
			temp+=to_string(a); 
			temp+=show(flag);
			temp+=to_string(b); 
			temp+="=";
			temp+=to_string(r); 
			int length=temp.length();
			rr+=temp;
			rr+='\n';
			rr+=to_string(length);
			rr+='\n';
			continue;
		}else{
			istringstream ss(str);
			vector<string> words;
			string word;
			while(ss >> word) {
				words.push_back(word);
			}
			int a=stoi(words[0]);
			int b=stoi(words[1]);
			int r=calc(a,b,flag);
			//cout<<a<<show(flag)<<b<<"="<<r;
			string temp;
			temp+=to_string(a); 
			temp+=show(flag);
			temp+=to_string(b); 
			temp+="=";
			temp+=to_string(r); 
			int length=temp.length();
			rr+=temp;
			rr+='\n';
			rr+=to_string(length);
			rr+='\n';
			continue;		
		}
	}
	cout<<rr;
	return 0;
}

int calc(int a,int b,char method){
	if(method=='a'){
		return a+b;
	} 
	if(method=='b'){
		return a-b;
	}
	if(method=='c'){
		return a*b;
	}
}
char show(char x){
	if(x=='a'){
		return '+';
	}
	if(x=='b'){
		return '-';
	}
	if(x=='c'){
		return '*';
	}
}
2023/10/20 22:32
加载中...