PAT Class B Java Implementation_1011. A+B and C_11

1011. A+B and C (15)

time limit
150 ms
memory limit
65536 kB
code length limit
8000 B
Judgment procedure
Standard
author
HOU, Qiming

Given three integers A, B and C in the interval [-2 31 , 2 31 ], please determine whether A+B is greater than C.

Input format:

Enter the first line to give a positive integer T (<=10), which is the number of test cases. Then T groups of test cases are given, each group occupies one line, and A, B and C are given in order. Integers are separated by spaces.

Output format:

For each set of test cases, output "Case #X: true" in one line if A+B>C, otherwise output "Case #X: false", where X is the test case number (starting from 1).

Input sample:
4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
Sample output:
Case #1: false
Case #2: true
Case #3: true
Case #4: false


/*The only thing you need to pay attention to is that you have to use the long type to save the input data,
 * Because the addition of two 2^31 and saving in int type will overflow
 * */
import java.util.Scanner;
public class PAT_B_1011
{
	public static void main(String[] agrs)
	{
		Scanner in = new Scanner(System.in);
		long num = in.nextLong();
		for(int i = 0; i < num; i++)
		{
			long a = in.nextLong();//Save the input data
			long b = in.nextLong();
			long c = in.nextLong();
			boolean flag = (a + b > c);//Determine whether (a+b) is greater than c
			System.out.println("Case #" + (i+1) + ": " + flag);//Formatted output
		}
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326424395&siteId=291194637