import java.util.Scanner; /**  * @author Shayne  * @date 2019-08-26  */ public class Main {     public static void main(String[] args) {         String map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";         Scanner sc = new Scanner(System.in);         while (sc.hasNextLine()) {             String str = sc.nextLine();             if (str == null || str.equals("")) {                 System.out.println("输入有误,请重新输入");                 continue;             }             String last = "";             if (str.length() % 3 == 1) {                 last += "==";             } else if (str.length() % 3 == 2) {                 last += "=";             }             String binaryStr = "";             for (int i = 0; i < str.length(); i++) {                 String binary = Integer.toBinaryString(str.charAt(i));                 binaryStr += String.format("%08d", Integer.valueOf(binary));             }             if (binaryStr.length() % 24 != 0) {                 binaryStr += String.format("%0" + (24 - binaryStr.length() % 24) + "d", 0);             }             String result = "";             for (int i = 0; i < binaryStr.length() / 6; i++) {                 String tmp = binaryStr.substring(i * 6, (i + 1) * 6);                 Integer index = Integer.parseInt(tmp,2);                 result += map.charAt(index);             }             System.out.println(result.substring(0, result.length() - last.length()) + last);         }     } }
点赞 评论

相关推荐

04-25 19:29
已编辑
宁波大学 运营
被普调的六边形战士很高大:你我美牛孩
点赞 评论 收藏
分享
牛客网
牛客企业服务