我试图解决这个问题我得到了正确的答案但是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();
}
}