Advertisement
Guest User

From left to the right

a guest
May 27th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. package DataTypeMoreExercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class problem1 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.         int leftSum = 0;
  11.         int rightSum = 0;
  12.         boolean forRight = false;
  13.         boolean forLeft = true;
  14.  
  15.         while (n-- > 0) {
  16.             String input = scanner.nextLine();
  17.             for (int i = 0; i < input.length(); i++) {
  18.                 if (input.charAt(i) - 32 == 0) {
  19.                     forRight = true;
  20.                     forLeft = false;
  21.                     continue;
  22.                 }
  23.                 if (forLeft) {
  24.                     leftSum += input.charAt(i) - '0';
  25.                 }
  26.                 if (forRight) {
  27.                     rightSum += input.charAt(i) - '0';
  28.                 }
  29.             }
  30.             if(leftSum > rightSum){
  31.                 System.out.println(leftSum);
  32.                 leftSum = 0;
  33.                 rightSum = 0;
  34.                 forLeft = true;
  35.                 forRight = false;
  36.             }else{
  37.                 System.out.println(rightSum);
  38.                 leftSum = 0;
  39.                 rightSum = 0;
  40.                 forLeft = true;
  41.                 forRight = false;
  42.  
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement