注意一下输入,当时尝试了很多办法才解决的,我用了无关变量m和n存储空格
Problem StatementJoisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either +
or -
. Your task is to evaluate the formula instead of her.
- 1≦A,B≦109
- op is either
+
or-
.
The input is given from Standard Input in the following format:
A op BOutput
Evaluate the formula and print the result.
Sample Input 11 + 2Sample Output 1
3
Since 1+2=3, the output should be 3.
Sample Input 25 - 7Sample Output 2
-2
#include<cstdio>
int main()
{
int a,c;
char b,n,m;
int sum;
while(scanf("%d",&a)!=EOF)
{
scanf("%c",&m);
scanf("%c",&b);
scanf("%c",&n);
scanf("%d",&c);
if(b==43)
{
sum=a+c;
printf("%d\n",sum);
}
else
{
sum=a-c;
printf("%d\n",sum);
}
}
return 0;
}