样例全对,50分 蒟蒻求援
  • 板块P1689 方程求解
  • 楼主fmg93
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/12/19 19:42
  • 上次更新2024/12/19 22:31:52
查看原帖
样例全对,50分 蒟蒻求援
1377950
fmg93楼主2024/12/19 19:42
#include<bits/stdc++.h>
using namespace std;
int m=0,i=0,h,b,c,d,u=0,k=0,x,y,q=0;
string s;
int main(){
	getline(cin,s);
	m=s.size();
	h=s.find('?');
	d=s.find('=');
	if(s.find('+')<m)
	{
		b=s.find('+');
		u=1;
	}
	else if(s.find('-')<m)
	{
		b=s.find('-');
	}
	while(s[i]<'0'||s[i]>'9')
	{
		i++;
	}
	x=s[i]-'0';
	i++;
	while(s[i]>='0'&&s[i]<='9')
	{
		x=x*10+s[i]-'0';
		i++;
	}
	while(s[i]<'0'||s[i]>'9')
	{
		i++;
	}
	y=s[i]-'0';
	i++;
	while(s[i]>='0'&&s[i]<='9')
	{
		y=y*10+s[i]-'0';
		i++;
	}
	if(h>d)
	{
		cout<<x+y<<endl;
		return 0;
	}
	if(h<b&&u==1)
	{
		cout<<y-x<<endl;
		return 0;
	}
	if(h<b&&u==0)
	{
		cout<<y+x<<endl;
		return 0;
	}
	if(u==1)
	{
		cout<<y-x<<endl;
		return 0;
	}
	cout<<x-y<<endl;
    return 0;
}
2024/12/19 19:42
加载中...