Advertisement
Guest User

Untitled

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