75pts求助
查看原帖
75pts求助
1187187
i_is_ak_ioi楼主2023/11/5 00:16
#include<bits/stdc++.h>
using namespace std;
int main(){
	string n;
	getline(cin,n);
	int s=n.find_first_of("+-*/");
	int s1=n.find_first_of("=");
	int s2=n.find_first_of("?");
	if(n[s]=='+'){
		if(s2<s1){
			double h=0,h1=0;
			for(int i=n.length()-1;i>s1;i--)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			if(s2!=0){
				for(int i=0;i<s;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
			}
			else{
				for(int i=s+1;i<s1;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
			}
			cout<<fixed<<setprecision(2)<<h-h1;
		}
		else{
			double h=0,h1=0;
			for(int i=0;i<s;i++)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			for(int i=s+1;i<s1;i++)
				if(n[i]>='0'&&n[i]<='9')
					h1=h1*10+(n[i]-'0');
			cout<<fixed<<setprecision(2)<<h+h1;
		}
	}
	else if(n[s]=='-'){
		if(s2<s1){
			double h=0,h1=0;
			for(int i=n.length()-1;i>s1;i--)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			if(s2!=0){
				for(int i=0;i<s;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
				cout<<fixed<<setprecision(2)<<h1-h;
			}
			else{
				for(int i=s+1;i<s1;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
				cout<<fixed<<setprecision(2)<<h+h1;
			}
			
		}
		else{
			double h=0,h1=0;
			for(int i=0;i<s;i++)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			for(int i=s+1;i<s1;i++)
				if(n[i]>='0'&&n[i]<='9')
					h1=h1*10+(n[i]-'0');
			cout<<fixed<<setprecision(2)<<h-h1;
		}		
	}
	else if(n[s]=='*'){
		if(s2<s1){
			double h=0,h1=0;
			for(int i=n.length()-1;i>s1;i--)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			if(s2!=0){
				for(int i=0;i<s;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
				cout<<fixed<<setprecision(2)<<h*h1;
			}
			else{
				for(int i=s+1;i<s1;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
				cout<<fixed<<setprecision(2)<<h/h1;
			}
			
		}
		else{
			double h=0,h1=0;
			for(int i=0;i<s;i++)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			for(int i=s+1;i<s1;i++)
				if(n[i]>='0'&&n[i]<='9')
					h1=h1*10+(n[i]-'0');
			cout<<fixed<<setprecision(2)<<h*h1;
		}				
	}
	else{
		if(s2<s1){
			double h=0,h1=0;
			for(int i=n.length()-1;i>s1;i--)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			if(s2!=0){
				for(int i=0;i<s;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
				cout<<fixed<<setprecision(2)<<h1/h;
			}
			else{
				for(int i=s+1;i<s1;i++)
					if(n[i]>='0'&&n[i]<='9')
						h1=h1*10+(n[i]-'0');
				cout<<fixed<<setprecision(2)<<h*h1;
			}
			
		}
		else{
			float h=0,h1=0;
			for(int i=0;i<s;i++)
				if(n[i]>='0'&&n[i]<='9')
					h=h*10+(n[i]-'0');
			for(int i=s+1;i<s1;i++)
				if(n[i]>='0'&&n[i]<='9')
					h1=h1*10+(n[i]-'0');
			cout<<fixed<<setprecision(2)<<h/h1;
		}		
	}
	return 0;
}

WA on#7#8#11

2023/11/5 00:16
加载中...