Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //8. Еднакви двойки
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- int numberOfPairs = scanner.nextInt();
- int maxDiff = 0;
- int firstNumber = 0;
- int secondNumber = 0;
- int firstPairSum = 0;
- int secondPairSum = 0;
- int trueMaxDiff = 0;
- for (int i = 1; i <= numberOfPairs;i++) {
- firstNumber = scanner.nextInt();
- secondNumber = scanner.nextInt();
- if (i == 1) {
- firstPairSum = firstNumber + secondNumber;
- secondPairSum = 0;
- } else {
- secondPairSum = firstNumber + secondNumber;
- maxDiff = firstPairSum - secondPairSum;
- if (Math.abs(maxDiff) > trueMaxDiff) {
- trueMaxDiff = Math.abs(maxDiff);
- }
- firstPairSum = secondPairSum;
- }
- }
- if (trueMaxDiff == 0) {
- System.out.printf("Yes, value=%d", firstPairSum);
- } else {
- System.out.printf("No, maxdiff=%d", trueMaxDiff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement