package com.singleton;
import java.util.Scanner;
import java.util.Vector;
/**
题目2:
总共有10题,依次编号1-10,初始分数10分,答对一题分数变成双倍,答错一题,扣掉
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
Vector<String> v = new Vector<String>();
for (int i = 0; i < 1024; i++) {
int score = 10;
String s = Integer.toBinaryString(i);
int l = 10 - s.length();
for (int k = 0; k < l; k++) {
score = score - k - 1;
}
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '0')
score = score - j - l - 1;
else
score = score * 2;
}
if (str.equals(score + "")) {
v.add(s);
}
}
if(v.size() != 0){
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < 10 - v.get(i).length(); j++) {
System.out.print(0);
}
if (i == v.size() - 1) {
System.out.print(v.get(i));
continue;
}
System.out.print(v.get(i) + "|");
}
}else
System.out.println("0000000000");
}
}
import java.util.Scanner;
import java.util.Vector;
/**
题目2:
总共有10题,依次编号1-10,初始分数10分,答对一题分数变成双倍,答错一题,扣掉
当前题号的分数,现在输入一个得分,需输出题目应答的情况,0表示答错,1表示答对
输入 0 输出 0000111111 ...
如果找不到这个得分的,输出10个0就好
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
Vector<String> v = new Vector<String>();
for (int i = 0; i < 1024; i++) {
int score = 10;
String s = Integer.toBinaryString(i);
int l = 10 - s.length();
for (int k = 0; k < l; k++) {
score = score - k - 1;
}
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '0')
score = score - j - l - 1;
else
score = score * 2;
}
if (str.equals(score + "")) {
v.add(s);
}
}
if(v.size() != 0){
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < 10 - v.get(i).length(); j++) {
System.out.print(0);
}
if (i == v.size() - 1) {
System.out.print(v.get(i));
continue;
}
System.out.print(v.get(i) + "|");
}
}else
System.out.println("0000000000");
}
}