Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DataTypeMoreExercises;
- import java.util.Scanner;
- public class problem1 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int leftSum = 0;
- int rightSum = 0;
- boolean forRight = false;
- boolean forLeft = true;
- while (n-- > 0) {
- String input = scanner.nextLine();
- for (int i = 0; i < input.length(); i++) {
- if (input.charAt(i) - 32 == 0) {
- forRight = true;
- forLeft = false;
- continue;
- }
- if (forLeft) {
- leftSum += input.charAt(i) - '0';
- }
- if (forRight) {
- rightSum += input.charAt(i) - '0';
- }
- }
- if(leftSum > rightSum){
- System.out.println(leftSum);
- leftSum = 0;
- rightSum = 0;
- forLeft = true;
- forRight = false;
- }else{
- System.out.println(rightSum);
- leftSum = 0;
- rightSum = 0;
- forLeft = true;
- forRight = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement