9.17网易互娱第一题0ac,请大神指点为何?
自测情况都通过,但是提交后0ac,不知为何。 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Solution solution = new Solution(); int n = sc.nextInt(); for (int i = 0; i < n; i++) { solution.getNum(sc.next()); } } } class Solution{ public void getNum(String s){ StringBuilder sb = toBinaryString(s); StringBuilder ans = new StringBuilder(); char ch = ' '; for (int j = 0; j < sb.length(); j++) { if (sb.charAt(j) == ch) { continue; } ch = sb.charAt(j); ans.append(ch); } System.out.println(ans.toString()); } public StringBuilder toBinaryString(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { sb.append(toBinary(s.charAt(i) - '0')); } sb.reverse(); int idx = 0; while (sb.charAt(idx) == '0') { idx++; } sb.delete(0, idx); return sb; } public StringBuilder toBinary(int x) { StringBuilder sb = new StringBuilder(); while (x > 0) { sb.append(x % 2); x /= 2; } return sb.reverse(); } }
#Java求助##网易互娱##笔经#