Advertisement
psi_mmobile

Untitled

May 15th, 2022
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. //8.    Еднакви двойки
  2. public class MyClass {
  3.     public static void main(String args[]) {
  4.        java.util.Scanner scanner = new java.util.Scanner(System.in);
  5.        int numberOfPairs = scanner.nextInt();
  6.        int maxDiff = 0;
  7.        int firstNumber = 0;
  8.        int secondNumber = 0;
  9.        
  10.        int firstPairSum = 0;
  11.        int secondPairSum = 0;
  12.        
  13.        int trueMaxDiff = 0;
  14.        
  15.        for (int i = 1; i <= numberOfPairs;i++) {
  16.            firstNumber = scanner.nextInt();
  17.            secondNumber = scanner.nextInt();
  18.            if (i == 1) {
  19.                firstPairSum = firstNumber + secondNumber;
  20.                secondPairSum = 0;
  21.            } else {
  22.                secondPairSum = firstNumber + secondNumber;
  23.                maxDiff = firstPairSum - secondPairSum;
  24.                if (Math.abs(maxDiff) > trueMaxDiff) {
  25.                    trueMaxDiff = Math.abs(maxDiff);
  26.                }
  27.                firstPairSum = secondPairSum;
  28.            }
  29.        }
  30.        if (trueMaxDiff == 0) {
  31.            System.out.printf("Yes, value=%d", firstPairSum);
  32.        } else {
  33.            System.out.printf("No, maxdiff=%d", trueMaxDiff);
  34.        }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement