题解 | #压缩二维码#

压缩二维码

https://www.nowcoder.com/practice/1150d36c2cd64df9bf373988486c6723

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (sc.hasNext()) {
            String cur = sc.next();
            for (char c: cur.toCharArray()) {
                if (c == '.') {
                    sb.append(0);
                }
                else {
                    sb.append(1);
                }
            }
        }
        System.out.print(Integer.valueOf(sb.substring(0, 4),2));
        for (int i = 4; i < sb.length(); i += 4) {
            System.out.print(" " + Integer.valueOf(sb.substring(i, i + 4), 2));
        }
        
    }
}

全部评论

相关推荐

许愿ssp的咸鱼很不想泡池子:import python as pyhton
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务