全RE,下载的数据也是对的,在DEV上运行没问题。求解答
查看原帖
全RE,下载的数据也是对的,在DEV上运行没问题。求解答
383842
zmabc楼主2021/1/11 00:37
#include <iostream>
#include<queue>
#include <sstream>
#include <queue>
using namespace std;
int width(int x);
struct ys{
char c;
int number1;
int number2;
};
int main()
{
int n;
cin>>n;
cin.sync();/*这里不放这个输后面入时会有问题,输不进去*/ 
queue<ys> arr;
char c;
int num1;
int num2;
for(int i=0;i<n;++i){
	string s;
	getline(cin,s,'\n');
	stringstream os;
	os<<s;
	if(s[0]=='a'||s[0]=='b'||s[0]=='c'){
		os>>c>>num1>>num2;
	}
	else{
		c=arr.back().c;
		os>>num1>>num2;
	}
	ys temp={c,num1,num2};
	arr.push(temp);	
}
while(!arr.empty()){
	int temp;
	if(arr.front().c=='a'){
		temp=arr.front().number1+arr.front().number2;
		cout<<arr.front().number1<<"+"<<arr.front().number2<<"="<<temp<<endl;
		cout<<width(arr.front().number1)+width(arr.front().number2)+width(temp)+2<<endl;
	}
	else if(arr.front().c=='b'){     
		temp=arr.front().number1-arr.front().number2;
		cout<<arr.front().number1<<"-"<<arr.front().number2<<"="<<temp<<endl;
		cout<<width(arr.front().number1)+width(arr.front().number2)+width(temp)+2<<endl;
	}
	else if(arr.front().c=='c'){
		temp=arr.front().number1*arr.front().number2;
		cout<<arr.front().number1<<"*"<<arr.front().number2<<"="<<temp<<endl;
		cout<<width(arr.front().number1)+width(arr.front().number2)+width(temp)+2<<endl;
	}
	arr.pop();
}
return 0;
}
int width(int x )
{
	int width=0; 
	if(x<0) width++;
	while(x!=0){
		width++;
		x/=10;
	}
return width;
}
2021/1/11 00:37
加载中...