Rezultati

Up. imeNalogaJezikRezultatČas oddaje
snajper Sveti gral Java 100/100OK 10. maj '18 @ 19:04

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 42,445 MiB 0,000 s OK
#2 5/5 41,977 MiB 0,000 s OK
#3 5/5 38,844 MiB 0,000 s OK
#4 5/5 42,406 MiB 0,000 s OK
#5 5/5 39,652 MiB 0,000 s OK
#6 5/5 40,012 MiB 0,000 s OK
#7 5/5 43,797 MiB 0,000 s OK
#8 5/5 40,711 MiB 0,000 s OK
#9 6/6 42,590 MiB 0,000 s OK
#10 6/6 42,164 MiB 0,000 s OK
#11 6/6 38,289 MiB 0,000 s OK
#12 6/6 40,660 MiB 0,000 s OK
#13 6/6 39,770 MiB 0,000 s OK
#14 6/6 41,023 MiB 0,000 s OK
#15 6/6 43,344 MiB 0,000 s OK
#16 6/6 43,070 MiB 0,000 s OK
#17 6/6 42,156 MiB 0,000 s OK
#18 6/6 40,215 MiB 0,000 s OK

Ocenjevani program (SvetiGral.java):
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by snajper on 5/10/18.
 */
public class SvetiGral {

    public static void main(String[] args) {
        Scanner in;

        if (args.length == 0) {
            in = new Scanner(System.in);
        } else {
            try {
                in = new Scanner(new File(args[0]));
            } catch (FileNotFoundException e) {
                throw new Error();
            }
        }

        int n = in.nextInt();
        ArrayList<Integer> res = new ArrayList<>();

        int start = n - ((int) (Math.log10(n) + 1) * 9);
        int stop = n;

        for(int i = start; i < stop; i++) {
            if(sum(i) == n) {
                res.add(i);
            }
        }

        System.out.println(res.size());
        res.sort((integer, t1) -> (integer - t1));
        for(int i : res) {
            System.out.println(i);
        }
    }

    private static int sum(int num) {
        int sum = 0;

        for(int i = 1; i <= num; i *= 10){
            sum += (num % (i * 10)) / i;
        }

        return sum + num;
    }
}