Knowee
Questions
Features
Study Tools

Given 3 integers A, B, and C such that A < B < CFind the value of max(A, B, C) - min(A, B, C)Here max(A, B, C) denotes the maximum value among A, B, C while min(A, B, C) denotes the minimum value among A, B, C.Input FormatThe first line of input will contain a single integer T, denoting the number of test cases.Each test case consists of 3 integers A, B, C.41 3 105 6 73 8 92 5 6Constraints1 <= T <= 101 <= A, B, C <= 10Output Format9264Sample Input 041 3 105 6 73 8 92 5 6Sample Output 09264Explanation 0Test case 1: Here, max(1,3,10)=10 and min(1, 3, 10) = 1. Thus, the difference is 9Sample Input 132 5 102 6 93 4 9Sample Output 1876

Question

Given 3 integers A, B, and C such that A < B < CFind the value of max(A, B, C) - min(A, B, C)Here max(A, B, C) denotes the maximum value among A, B, C while min(A, B, C) denotes the minimum value among A, B, C.Input FormatThe first line of input will contain a single integer T, denoting the number of test cases.Each test case consists of 3 integers A, B, C.41 3 105 6 73 8 92 5 6Constraints1 <= T <= 101 <= A, B, C <= 10Output Format9264Sample Input 041 3 105 6 73 8 92 5 6Sample Output 09264Explanation 0Test case 1: Here, max(1,3,10)=10 and min(1, 3, 10) = 1. Thus, the difference is 9Sample Input 132 5 102 6 93 4 9Sample Output 1876

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

To find the value of max(A, B, C) - min(A, B, C), we need to compare the three given integers A, B, and C.

  1. Read the number of test cases, T.

  2. For each test case, read the values of A, B, and C.

  3. Calculate the maximum value among A, B, and C using the max() function. Let's call this value max_val.

  4. Calculate the minimum value among A, B, and C using the min() function. Let's call this value min_val.

  5. Subtract min_val from max_val to get the desired result.

  6. Print the result for each test case.

Here is the step-by-step solution for the given sample input:

Test case 1: A = 41, B = 3, C = 10

max_val = max(41, 3, 10) = 41 min_val = min(41, 3, 10) = 3

Result = max_val - min_val = 41 - 3 = 38

Print the result: 38

Test case 2: A = 5, B = 6, C = 7

max_val = max(5, 6, 7) = 7 min_val = min(5, 6, 7) = 5

Result = max_val - min_val = 7 - 5 = 2

Print the result: 2

Test case 3: A = 3, B = 8, C = 9

max_val = max(3, 8, 9) = 9 min_val = min(3, 8, 9) = 3

Result = max_val - min_val = 9 - 3 = 6

Print the result: 6

Test case 4: A = 2, B = 5, C = 6

max_val = max(2, 5, 6) = 6 min_val = min(2, 5, 6) = 2

Result = max_val - min_val = 6 - 2 = 4

Print the result: 4

Therefore, the final output is: 38 2 6 4

This problem has been solved

Similar Questions

Write a function which takes three integers as arguments, and returns the maximum of the three. The main() function then tests this function appropriately.

Problem StatementWrite a program that accepts sets of three numbers, and prints the second-maximum number among the three.InputFirst line contains the number of triples, N.The next N lines which follow each have three space separated integers.OutputFor each of the N triples, output one new line which contains the second-maximum integer among the three.Constraints1 ≤ N ≤ 61 ≤ every integer ≤ 10000The three integers in a single triplet are all distinct. That is, no two of them are equal.Sample 1:InputOutput31 2 310 15 5100 999 500210500

Given 2 numbers - A and B, evaluate AB.Note:Do not use any inbuilt functions / libraries for your main logic.Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each line containing 2 numbers - A and B, separated by space.Output FormatFor each test case, print AB, separated by new line. Since the result can be very large, print result % 1000000007Constraints30 points1 <= T <= 10000 <= A <= 1060 <= B <= 10370 points1 <= T <= 10000 <= A <= 1060 <= B <= 109ExampleInput45 21 102 3010 10Output25173741817999999937

Find the cube root of the given number. Assume that all the input test cases will be a perfect cube.Note: Do not use any inbuilt functions / libraries for your main logic.Input FormatThe first line of input contains T - the number of test cases. It is followed by T lines, each containing a single integer.Output FormatFor each test case, print the cube root of the number, separated by a new line.Constraints30 points1 <= T <= 103-109 <= N <= 10970 points1 <= T <= 106-1018 <= N <= 1018ExampleInput5-27-12510006859-19683Output-3-51019-27

You are given an array 𝐴A of length 𝑁N, and an integer 𝐾K.You can perform the following operation:Choose any index 𝑖i (1≤𝑖≤𝑁1≤i≤N), and increase 𝐴𝑖A i​ by 𝐾K.Find the minimum possible value of max⁡(𝐴)−min⁡(𝐴)max(A)−min(A) attainable, if you can perform this operation as many times as you like (possibly, zero times).Input FormatThe first line of input will contain a single integer 𝑇T, denoting the number of test cases.Each test case consists of two lines of input.The first line of each test case contains two space-separated integers 𝑁N and 𝐾K — the length of the array and the parameter 𝐾K.The second line contains 𝑁N space-separated integers 𝐴1,𝐴2,…,𝐴𝑁A 1​ ,A 2​ ,…,A N​ — the initial values of the array elements.Output FormatFor each test case, output on a new line the answer: the minimum possible value of max⁡(𝐴)−min⁡(𝐴)max(A)−min(A) if you can perform the given operation any number of times.Constraints1≤𝑇≤1051≤T≤10 5 1≤𝑁≤2⋅1051≤N≤2⋅10 5 1≤𝐾≤1091≤K≤10 9 1≤𝐴𝑖≤1091≤A i​ ≤10 9 The sum of 𝑁N over all test cases won't exceed 2⋅1052⋅10 5 .Sample 1:InputOutput43 41 5 43 212 8 44 11 43 62 8256 121 2 4 128 130 1311008Explanation:Test case 11: Increase the first element by 𝐾=4K=4 to obtain the array [5,5,4][5,5,4].Here, max⁡−min⁡=5−4=1max−min=5−4=1, which is the best possible.Test case 22: The second and third elements can be increased by 22 till they reach 1212, at which point all the elements of the array are equal, so max⁡(𝐴)−min⁡(𝐴)=0max(A)−min(A)=0.Test case 33: Since 𝐾=1K=1, again it's possible to make all the elements equal.Test case 44: Do the following:Increase 𝐴1A 1​ by 1212 repeatedly to make it 133133.Increase 𝐴2A 2​ by 1212 repeatedly to make it 134134.Increase 𝐴3A 3​ by 1212 repeatedly to make it 136136.The array is now [133,134,136,128,130,131][133,134,136,128,130,131].For this array, max⁡(𝐴)−min⁡(𝐴)=136−128=8max(A)−min(A)=136−128=8.It can be shown that this is optimal.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.