题解 | #扭蛋机#
扭蛋机
https://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7
纪念第一题写出来了
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static StringBuilder sb=new StringBuilder();
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int target=in.nextInt();
count2233(target);
System.out.println(sb.toString());
}
public static void count2233(int target){
if (target==1){
sb.insert(0,2);
return;
}
if (target==2){
sb.insert(0,3);
return;
}
if (target%2==0){
sb.insert(0,3);
count2233((target-2)/2);
}else {
sb.insert(0,2);
count2233((target-1)/2);
}
}
}