题解 | #扭蛋机#

扭蛋机

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);
        }
    }

}

全部评论

相关推荐

白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
点赞 评论 收藏
分享
牛客928043833号:在他心里你已经是他的员工了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务