Editorial for Balanced Numbers


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: doncho

Sample solutions:

Video in BG

JavaScript

let sum = 0;

while (true) {
    let [x, y, z] = gets();
    if (+x + +z !== +y) {
        break;
    }
    sum += +(x + y + z);
}

print(sum);

Java

import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int sum = 0;

    while (true) {
      String number = in.nextLine();
      int a = number.charAt(0) - '0';
      int b = number.charAt(1) - '0';
      int c = number.charAt(2) - '0';

      if (a + c != b) {
        break;
      }

      sum += Integer.parseInt(number);
    }

    System.out.println(sum);
  }
}

Comments

There are no comments at the moment.