关注
import java.util.Scanner;
import java.util.Vector;
public class Main { static public void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); while (n-- > 0) { // 第一次 补齐0 String string = in.nextLine(); if (string.length() % 3 == 1) { string = "00" + string; } else if (string.length() % 3 == 2) { string = "0" + string; } // 将十进制转换成2进制 Vector<String> vector = new Vector<>(); int threeNum = string.length() / 3; String tenStr = ""; for (int i = 0; i < threeNum; i++) { String temp = string.substring(i * 3, i * 3 + 3); temp = Integer.toString(Integer.parseInt(temp), 2); int tempLen = temp.length(); for (int j = 0; j < 10 - tempLen; j++) { temp = "0" + temp; } tenStr = tenStr + temp; } // 去掉前导零 int tenStrLen = tenStr.length(); String tempStr = tenStr; for (int i = 0; i < tenStrLen; i++) { if (tenStr.charAt(i) == '0') { tempStr = tenStr.substring(i + 1, tenStrLen); } else { break; } } tenStr = tempStr; tenStrLen = tenStr.length(); for (int i = 0; i < tenStrLen; i++) { if (tenStr.charAt(i) == '0') { tempStr = tenStr.substring(i + 1, tenStrLen); } else { break; } } tenStrLen = tenStr.length(); int howManyFive = tenStr.length() % 5; if (howManyFive != 0) { while (howManyFive++ < 5) { tenStr = "0" + tenStr; } } String result = ""; tenStrLen = tenStr.length(); int fiveTime = tenStrLen / 5; while (fiveTime-- > 0) { result = Integer.toString(Integer.parseInt(tenStr.substring(5 * fiveTime, 5 * fiveTime + 5), 2), 32) + result; } System.out.println(result.toUpperCase()); } }
}
第二题 可以优化的点太多了……懒得继续优化了
查看原帖
点赞 1
相关推荐
战争学院:你妈妈第一反应是骗子,我妈妈第一反应是培训贷,全国家长系统是统一的吗哈哈哈
点赞 评论 收藏
分享
04-30 22:30
岭南师范学院 Java 点赞 评论 收藏
分享
牛客热帖
更多
- 1... 我进字节她考编,明知要分手但确没人敢开口1.6W
- 2... 从java跑路做ai了1.5W
- 3... 全网征集:实习/春招投递进度记录,最高可得20元现金!1.5W
- 4... 如何利用skill写出一份好简历1.4W
- 5... 离开华为一年多,说说我的真实感受6060
- 6... 双非本鼠鼠被字节回捞了,uu们接好运吧!5721
- 7... 女朋友说先各自工作一年再决定,啥意思?5436
- 8... 27届实习投递总结贴:AI/算法/数据方向,简历挂和一面挂都记录一下4815
- 9... 被妈妈说的感觉自己好没用啊😭4696
- 10... 计算机怎么转行半导体呢?4535
正在热议
更多
# 我的求职总结 #
481794次浏览 6813人参与
# 投格力的你,拿到offer了吗? #
187690次浏览 915人参与
# 27届实习投递记录 #
78786次浏览 866人参与
# 我是XXX,请攻击我最薄弱的地方 #
92646次浏览 626人参与
# 26届春招投递记录 #
13237次浏览 88人参与
# 中电科13所进度交流 #
6997次浏览 39人参与
# 风评不好的公司,你会去吗? #
155445次浏览 706人参与
# 哪一瞬间让你觉得“这班不如不上” #
46817次浏览 279人参与
# 入职第四天,心情怎么样 #
56593次浏览 475人参与
# 拼多多工作体验 #
62021次浏览 435人参与
# 产品面经 #
297654次浏览 2217人参与
# 海信求职进展汇总 #
105915次浏览 424人参与
# 这些公司卡简历很严格 #
107687次浏览 495人参与
# 美团开奖 #
417137次浏览 1818人参与
# 字节7000实习来了,你投了吗? #
59999次浏览 457人参与
# 总结:offer选择,我是怎么选的 #
297695次浏览 1596人参与
# AI让海力士市值突破9000亿美元 #
9644次浏览 124人参与
# 牛油的搬砖plog #
206495次浏览 1332人参与
# 小厂实习有必要去吗 #
94597次浏览 449人参与
# 正在实习的你,几点下班 #
355218次浏览 3072人参与
