来自Codechef的Ciel和Receipt - 得到正确的答案,但Codechef说错了,任何错误我都看不到?

时间:2016-05-25 14:39:15

标签: java

我试图解决这个问题我得到了正确的答案但是codechef说错了每次都可以帮助我解决这个问题 https://www.codechef.com/problems/CIELRCPT 我的代码如下:

import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        int input;
        int divisor[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 };
        while (testCases-- > 0) {
            input = sc.nextInt();
            int count = 0;
            int temp = 0;
            for (int i = 11; i >= 0; i--) {

                if (input > 2048) {
                    input = (int) (input - divisor[i]);
                    count++;

                }
                if (input >= divisor[i] && temp + divisor[i] <= input) {

                    temp += divisor[i];
                    count++;

                }

            }

            System.out.println(count);

        }
        sc.close();
    }
}

0 个答案:

没有答案