本文主要是介绍codeforces 479A(Expression) Java,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
暴力虐水题!!!
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;/*** 题意:给出三个数要求添加运算符(+,*),使其计算结果要最大。一定要所有情况都考虑到** @author TinyDolphin* 2017/7/2 20:10.*/
public class Main {public static void main(String[] args) throws IOException {Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));int[] input = new int[3]; //存放输入的三个数int maxSum;while (in.hasNext()) {for (int index = 0; index < 3; index++) {input[index] = in.nextInt();}if (input[0] == 1 && input[1] != 1 && input[2] != 1) {maxSum = (input[0] + input[1]) * input[2];} else if (input[0] != 1 && input[1] == 1 && input[2] != 1) {if (input[0] < input[2]) {maxSum = (input[0] + input[1]) * input[2];} else {maxSum = input[0] * (input[1] + input[2]);}} else if (input[0] != 1 && input[1] != 1 && input[2] == 1) {maxSum = input[0] * (input[1] + input[2]);} else if (input[0] == 1 && input[1] == 1 && input[2] != 1) {maxSum = (input[0] + input[1]) * input[2];} else if (input[0] == 1 && input[1] != 1 && input[2] == 1) {maxSum = input[0] + input[1] + input[2];} else if (input[0] != 1 && input[1] == 1 && input[2] == 1) {maxSum = input[0] * (input[1] + input[2]);} else if (input[0] == 1 && input[1] == 1 && input[2] == 1) {maxSum = input[0] + input[1] + input[2];} else {maxSum = input[0] * input[1] * input[2];}out.println(maxSum);}out.flush();}
}
这篇关于codeforces 479A(Expression) Java的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!