Advertisement
ralitsa_d

SameCouples

Feb 8th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pr12SameCouples {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scan.nextLine());
  8.  
  9. int prevSum = Integer.parseInt(scan.nextLine()) + Integer.parseInt(scan.nextLine());
  10.  
  11. int maxDiff = 0;
  12.  
  13. for (int i = 0; i < n - 1; i++) {
  14. int currentSum = Integer.parseInt(scan.nextLine()) +Integer.parseInt(scan.nextLine());
  15.  
  16. int diff = Math.abs(currentSum - prevSum);
  17.  
  18. if(diff != 0){
  19. if(diff > maxDiff){
  20. maxDiff = diff;
  21. }
  22. }
  23.  
  24. prevSum = currentSum;
  25. }
  26.  
  27. if(maxDiff == 0){
  28. System.out.printf("Yes, value=%s", prevSum);
  29. } else {
  30. System.out.printf("No, maxdiff=%s", maxDiff);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement