求助,92pts,WA on test 5
查看原帖
求助,92pts,WA on test 5
233815
zhjzhmh楼主2020/10/8 07:45
#include<bits/stdc++.h>
#define pr(x) printf("%.2lf",x);
using namespace std;
string st;
double s1,s2,s3,js,x;
int main()
{
	getline(cin,st);
	int i=0;
	while(st[i]==' ') i++;
	if(st[i]=='?') x=1,i++;
	else
	{
		s1=st[i]-'0';
		while(1)
		{
			i++;
			if(i>st.size()-1||st[i]>'9'||st[i]<'0') break;
			  else s1=s1*10+st[i]-'0';
		}
	}
	while(st[i]==' ') i++;
	if(st[i]=='+') js=1;
	if(st[i]=='-') js=2;
	if(st[i]=='*') js=3;
	if(st[i]=='/') js=4;
	i++;
	while(st[i]==' ') i++;
	if(st[i]=='?') x=2,i++;
	else
	{
		s2=st[i]-'0';
		while(1)
		{
			i++;
			if(i>st.size()-1||st[i]>'9'||st[i]<'0') break;
			  else s2=s2*10+st[i]-'0';
		}
	}
	while(st[i]==' ') i++;
	i++;
	while(st[i]==' ') i++;
	if(st[i]=='?') x=3,i++;
	else
	{
		s3=st[i]-'0';
		while(1)
		{
			i++;
			if(i>st.size()-1||st[i]>'9'||st[i]<'0') break;
			  else s3=s3*10+st[i]-'0';
		}
	}
	if(js==1) 
	{
		if(x==1) pr(s3-s2);
		if(x==2) pr(s3-s1);
		if(x==3) pr(s1+s2);
	} 
	if(js==2) 
	{
		if(x==1) pr(s3+s2);
		if(x==2) pr(s1-s2);
		if(x==3) pr(s1-s2);
	}
	if(js==3) 
	{
		if(x==1) pr(1.0*s3/s2);
		if(x==2) pr(1.0*s3/s1);
		if(x==3) pr(s1*s2);
	}
	if(js==4) 
	{
		if(x==1) pr(s3*s2);
		if(x==2) pr(1.0*s1/s3);
		if(x==3) pr(1.0*s1/s2);
	}
	return 0;
}
2020/10/8 07:45
加载中...