Advertisement
Spocoman

08. Equal Pairs

Aug 28th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  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 num = Integer.parseInt(scanner.nextLine());
  7.         int equalValue = Integer.parseInt(scanner.nextLine()) + Integer.parseInt(scanner.nextLine());
  8.         int maxiff = 0;
  9.         int maxDiff = 0;
  10.  
  11.         for (int i = 1; i < num; i++) {
  12.             int currentValue = Integer.parseInt(scanner.nextLine()) + Integer.parseInt(scanner.nextLine());
  13.             int currentDiff = Math.abs(equalValue - currentValue);
  14.  
  15.             if (currentDiff > maxDiff) {
  16.                 maxDiff = currentDiff;
  17.             } else {
  18.                 equalValue = currentValue;
  19.             }
  20.         }
  21.      
  22.         if (maxDiff == 0) {
  23.             System.out.printf("Yes, value=%d", equalValue);
  24.         } else {
  25.             System.out.printf("No, maxdiff=%d", maxDiff);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement