beinsaduno

E06EqualSum

Jan 22nd, 2021
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E06EqualSum {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String[] input = scanner.nextLine().split(" ");
  8.         int[] arr = new int[input.length];
  9.  
  10.         int sumRight = 0;
  11.         int sumLeft = 0;
  12.         int index = 0;
  13.         boolean isNotEqual = false;
  14.  
  15.  
  16.         for (int i = 0; i < input.length; i++) {
  17.             arr[i] = Integer.parseInt(input[i]);
  18.         }
  19.  
  20.         for (int i = 0; i < input.length; i++) {
  21.             index = i;
  22.             if (i > 0) {
  23.                 sumLeft += arr[i - 1];
  24.                 for (int j = i + 1; j < input.length; j++) {
  25.                     sumRight += arr[j];
  26.                 }
  27.                 if (sumLeft == sumRight) {
  28.                     System.out.println(index);
  29.                     return;
  30.                 } else if(sumLeft != sumRight) {
  31.                     isNotEqual = true;
  32.                 }
  33.                 sumRight = 0;
  34.             }
  35.         }
  36.         if (index == 0) {
  37.             System.out.println(index);
  38.         }
  39.         if (isNotEqual){
  40.             System.out.println("no");
  41.         }
  42.     }
  43. }
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment