F - Addition and Subtraction Easy
2018-03-12 07:35
465 查看
注意一下输入,当时尝试了很多办法才解决的,我用了无关变量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
Constraints1≦A,B≦109
op is either
InputThe input is given from Standard Input in the following format:A op B
OutputEvaluate the formula and print the result.
Sample Input 1
Sample Input 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;
}
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.
Constraints1≦A,B≦109
op is either
+or
-.
InputThe input is given from Standard Input in the following format:A op B
OutputEvaluate the formula and print the result.
Sample Input 1
1 + 2Sample Output 1
3Since 1+2=3, the output should be 3.
Sample Input 2
5 - 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;
}
相关文章推荐
- 592. Fraction Addition and Subtraction
- 592. Fraction Addition and Subtraction
- 592. Fraction Addition and Subtraction
- [arc066e]Addition and Subtraction Hard
- leetcode 592. Fraction Addition and Subtraction
- leetcode-592. Fraction Addition and Subtraction
- [leetcode]592. Fraction Addition and Subtraction
- leetcode 592. Fraction Addition and Subtraction 分数加法+C++stringstream的一个很好的示例
- Binary search with addition and subtraction
- AtCoder Regular Contest 066 E - Addition and Subtraction Hard 动态规划
- [Leetcode] 592. Fraction Addition and Subtraction 解题报告
- algorithm 1.4.22 Binary search with only addition and subtraction
- CareerCup Find whether a given number is a perfect square or not.(Addition and Subtraction only)
- AtCoder Regular Contest 066 E - Addition and Subtraction Hard
- Output result string after numbers addition and subtraction
- Fraction Addition and Subtraction
- Math-592-Fraction Addition and Subtraction
- [LeetCode] Fraction Addition and Subtraction 分数加减法
- 大数据加减(Big data addition and subtraction)
- Fraction Addition and Subtraction