ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

Help!I can not figure out about the limited time.
Posted by Hunter 20 Apr 2016 20:09
import java.util.Scanner;

public class Digitals {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int a[] = new int[N];
        int b[] = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            a[i] = in.nextInt();
            sum = 1;
            for (int j = 0;; j++) {
                sum = sum + j;
                if (sum == a[i]) {
                    b[i] = 1;
                    break;
                }
                if (sum > a[i]) {
                    b[i] = 0;
                    break;
                }
            }
        }
        for (int p = 0; p < N - 1; p++)
            System.out.print(b[p] + " ");
        System.out.println(b[N - 1]);
        in.close();
    }
}