自己目前可以做到一层变换。 public static void main(String args[]) { Scanner cin = new Scanner(System.in); int in = cin.nextInt(); //先转换为二进制数 char[] ch = Integer.toBinaryString(in).toCharArray(); String res = ""; //记录从左到右的幂次位数 int temp = ch.length - 1; for (int i = 0; i < ch.length; i++) { if (ch[i] == '1') { if(res == "") { res += "2(" + temp + ")"; } else { res += "+" + "2(" + temp + ")"; } } temp--; } System.out.println(res); cin.close(); }
点赞 1

相关推荐

不愿透露姓名的神秘牛友
昨天 20:08
滴滴 网约车 240-300 其他
点赞 评论 收藏
分享
野猪不是猪🐗:现在的环境就是这样,供远大于求。 以前卡学历,现在最高学历不够卡了,还要卡第一学历。 还是不够筛,于是还要求得有实习、不能有gap等等... 可能这个岗位总共就一个hc,筛到最后还是有十几个人满足这些要求。他们都非常优秀,各方面都很棒。 那没办法了,看那个顺眼选哪个呗。 很残酷,也很现实
点赞 评论 收藏
分享
牛客网
牛客企业服务