题解 | 字符串解密

字符串解密

https://www.nowcoder.com/practice/20c87a5d601f4999933ba100d6a53788

Integer中提供字符串按照二进制转化为十进制的方法


import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder sb = new StringBuilder(s.trim());

        int count = 0;
        ArrayList<Integer> result = new ArrayList<>();
        lable:
        while(true){
            for (int i = 1; i < 11; i++) {
                if(i > sb.length()){
                    break lable;
                }
                count++;
                int num = Integer.parseInt(sb.substring(0,i),2);
                result.add(num);
                sb.delete(0,i);
            }
        }
        System.out.println(count);
        for (Integer res : result) {
            System.out.print(res+" ");
        }
    }
    
}

全部评论

相关推荐

04-15 13:42
四川大学 Java
蹲蹲offerrr:快投吧,有点晚现在
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务