SHARE
TWEET

Equal Pairs [Mimi][PB]

damesova May 23rd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class EqualPairs {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         int sum1 = 0;
  9.         int sum2 = 0;
  10.         int diff = 0;
  11.  
  12.         for (int i = 1; i <= n; i++) {
  13.             int num1 = Integer.parseInt(scanner.nextLine());
  14.             int num2 = Integer.parseInt(scanner.nextLine());
  15.  
  16.             if (i % 2 == 0) {
  17.                 sum2 = num1 + num2;
  18.             } else {
  19.                 sum1 = num1 + num2;
  20.             }
  21.             if (i > 1 && Math.abs(sum2 - sum1) > diff) {
  22.                 diff = Math.abs(sum2 - sum1);
  23.             }
  24.  
  25.         }
  26.  
  27.         if (diff == 0) {
  28.             System.out.println("Yes, value=" + sum1);
  29.         } else {
  30.             System.out.println("No, maxdiff=" + diff);
  31.         }
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top