时间限制: 1 Sec 内存限制: 128 MB
题目描述
msh:will,这题怎么做啊?
will:看论文去。
ql:msh,这题怎么做啊?
will:这么简单的题都不会啊!
jzt:ql,这题怎么做啊?
will:哈哈,你等着,看哥来教你。
一日,再一次被bs之后,大家终于忍无可忍了。决定出点题难住will,好打压一下will嚣张的气焰。
不过,由于大家的智商有限,只会加减法,经过商讨,总是让will回答诸如a+b或者a-b之类的问题,似乎难不住他。终于,jzt想到一个很NB的办法:让他算a+?=b。jzt:这么NB的难题都被我想到了,哈哈!
will:这种题,看论文去……
输入
输入一个等式,形如A+B=C或A-B=C。给定其中的两个数,请确定其中的第三个数。其中0<=A,B,C<1,000,000,000,没有给定的数用一个单独的“?”表示,等式中没有多余空格。
输出
直接输出要求的第三个数,用回车结尾。
样例输入
【样例1】
1+2=?
【样例2】
1+?=3
样例输出
【样例1】
3
【样例2】
2
单纯的一道模拟题,就是代码写的有点。。。qwq
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <vector>
#include <queue>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 1005
using namespace std;
int main()
{
char str[50]= {'\0'};
scanf("%s",str);
//printf("%s",str);
ll a=0,b=0,c=0,i,j;
int next=0;
int len=strlen(str);
int fuhao=1;
if(str[0]=='?')
{
if(str[1]=='-')
fuhao=-1;
for(i=2; str[i]!='\0'; i++)
{
if(!next&&str[i]>='0'&&str[i]<='9')
{
a=10*a+str[i]-'0';
}
if(str[i]=='=')
{
next=1;
i++;
}
if(next&&str[i]>='0'&&str[i]<='9')
{
b=b*10+str[i]-'0';
}
}
if(fuhao==1)
printf("%lld\n",b-a);
else
printf("%lld",a+b);
}
else if(str[len-1]!='?')
{
for(i=0; str[i]!='\0'; i++)
{
if(!next&&str[i]>='0'&&str[i]<='9')
{
a=10*a+str[i]-'0';
}
if(str[i]=='+'&&str[++i]=='?')
{
next=1;
}
if(str[i]=='-'&&str[++i]=='?')
{
fuhao=-1;
next=1;
}
if(next&&str[i]>='0'&&str[i]<='9')
b=b*10+str[i]-'0';
}
if(fuhao==1)
printf("%lld\n",b-a);
else
printf("%lld\n",a-b);
}
else
{
for(i=0; str[i]!='\0'; i++)
{
if(!next&&str[i]>='0'&&str[i]<='9')
{
a=10*a+str[i]-'0';
}
if(str[i]=='+')
{
next=1;
i++;
}
if(str[i]=='-')
{
fuhao=-1;
next=1;
i++;
}
if(next&&str[i]>='0'&&str[i]<='9')
{
b=10*b+str[i]-'0';
}
}
if(fuhao==1)
printf("%lld\n",a+b);
else
printf("%lld\n",a-b);
}
return 0;
}