Advertisement
borkins

12. Equal Pairs

Mar 30th, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. /**
  2.  * Project: Loops - created by borkins on 2017-03-30.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _12_EqualPairs
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int n = Integer.parseInt(console.nextLine());
  14.        
  15.         int pairSum = 0;
  16.         int maxDiff = 0;
  17.         int lastSum = 0;
  18.        
  19.         for (int i = 0; i < n; i++)
  20.         {
  21.             int a = Integer.parseInt(console.nextLine());
  22.             int b = Integer.parseInt(console.nextLine());
  23.            
  24.             pairSum = a + b;
  25.            
  26.             if (i > 0) {
  27.                 int diff = Math.abs(pairSum - lastSum);
  28.                
  29.                 if (diff > maxDiff) maxDiff = diff;
  30.             }
  31.             lastSum = pairSum;
  32.         }
  33.  
  34.         System.out.println((maxDiff == 0) ?
  35.                            "Yes, value=" + pairSum : "No, maxdiff=" + maxDiff);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement