Advertisement
KeepCoding

EqualPairs

Nov 28th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EqualPairs {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(console.nextLine());
  8.         int n2 = 0;
  9.         int n1 = 0;
  10.         int sum1 = 0;
  11.         int sum2 = 0;
  12.         int max = 0;
  13.        for (int i = 0; i < n; i++) {
  14.             if (i % 2 == 0) {
  15.                 n1 = Integer.parseInt(console.nextLine());
  16.                 n2 = Integer.parseInt(console.nextLine());
  17.                 sum2 = n1 + n2;
  18.             } else {
  19.                 n1 = Integer.parseInt(console.nextLine());
  20.                 n2 = Integer.parseInt(console.nextLine());
  21.                 sum1 = n1 + n2;
  22.             }
  23.  
  24.             if (i > 0) { //minala e purva i vtora iteraciq
  25.                 if (sum1 != sum2) {
  26.                    if (Math.abs(sum1 - sum2) > max) {
  27.                         max = Math.abs(sum1 - sum2);
  28.                     }
  29.  
  30.                 }
  31.             }
  32.  
  33.         }
  34.         if (max == 0) {
  35.             System.out.println("Yes, value=" + sum2);
  36.         } else {
  37.             System.out.println("No, maxdiff=" + max);
  38.         }
  39.  //code ends here
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement