Advertisement
desislava_topuzakova

Untitled

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