Rezultati

Up. imeNalogaJezikRezultatČas oddaje
javanskivaljar-2018 Sveti gral Java 100/100OK 10. maj '18 @ 17:26

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 39,613 MiB 0,000 s OK
#2 5/5 36,156 MiB 0,000 s OK
#3 5/5 37,199 MiB 0,000 s OK
#4 5/5 35,840 MiB 0,000 s OK
#5 5/5 38,422 MiB 0,000 s OK
#6 5/5 37,316 MiB 0,000 s OK
#7 5/5 36,867 MiB 0,000 s OK
#8 5/5 36,836 MiB 0,000 s OK
#9 6/6 39,012 MiB 0,000 s OK
#10 6/6 38,160 MiB 0,000 s OK
#11 6/6 36,254 MiB 0,000 s OK
#12 6/6 37,789 MiB 0,000 s OK
#13 6/6 33,688 MiB 0,000 s OK
#14 6/6 36,375 MiB 0,000 s OK
#15 6/6 38,289 MiB 0,000 s OK
#16 6/6 36,410 MiB 0,000 s OK
#17 6/6 37,961 MiB 0,000 s OK
#18 6/6 37,660 MiB 0,000 s OK

Ocenjevani program (SvetiGral.java):
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * Created by javanskivaljar-2018 on 5/10/18.
 */
public class SvetiGral {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 0){
            System.out.println("1");
            System.out.println("0");
            System.exit(0);
        }
        ArrayList<Integer> Resitve = new ArrayList<Integer>();
        int m = (int) Math.log10( n);
        m+=1;
        for(int i = n; i >= n - 10*m && i >= 0; i--) {
            if(Veljaven(i, n)) {
                Resitve.add(i);
            }
        }
        Collections.sort(Resitve);
        System.out.println(Resitve.size());
        for(int r : Resitve){
            System.out.println(r);
        }
    }
    public static int NumberDigitSum2(int Number)
    {
        int DigitSum = 0;
        while(Number > 0){
            DigitSum += Number % 10;
            Number /= 10;
        }
        return DigitSum;
    }
    public static boolean Veljaven(int i, int n) {
        return (i + NumberDigitSum2(i) == n);
    }
}
/*public static int NumberDigitSum(int Number){
    int DigitSum = 0;
    int i = 0;
    int NumberCopy = Number;
    int NumberLength = 0;
    int PowerOfTen = 1;
    while(Number != 0){
        NumberLength++;
        Number /= 10;
        PowerOfTen *= 10;
    }
    Number = NumberCopy;
    for(int i = 0; i < NumberLength ;i++){
        DigitSum += Number / PowerOfTen;
        Number %= PowerOfTen;
    }*/