Time limit : 2sec / Memory limit : 1024MB
Score : 100 points
Problem Statement
You are given two integers A and B. Find the largest value among A+B, A−B and A×B.
Constraints
- −1000≤A,B≤1000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the largest value among A+B, A−B and A×B.
Sample Input 1
3 1
Sample Output 1
4
3+1=4, 3−1=2 and 3×1=3. The largest among them is 4.
Sample Input 2
4 -2
Sample Output 2
6
The largest is 4−(−2)=6.
Sample Input 3
0 0
Sample Output 3
0
[题目解释]
给你两个整数A,B在A+B,A-B,A*B中寻找最大值(-1000≤a,b≤1000,且a,b为整数)
[题目解析]
读入两个整数A,B分别算出A+B,A-B,A*B的数值后,取最大值记录在ans里即可
[代码]
/* Name: Add Sub Mul Author: FZSZ-LinHua Date: 2018 06 06 Exec time: 1ms Memory usage: 128KB Score: 100 Algorithm: Brute-force */ # include "cstdio" # define max(a,b) ((a)>(b)?(a):(b)) int main(){ int a,b,ans; scanf("%d%d",&a,&b); //输入两个整数 ans=max(a+b,max(a-b,a*b)); //等价于取a+b,a-b,a*b的最大值并存入ans中 printf("%d",ans); //打印答案 return 0; }
注意:代码中的max也可以用"iostream"库中的max函数