Loading...

3789 -- バイナリークロック

問題文を読まずにチャレンジ。
3789 -- Binary Clock
package p3789; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int i =1; while(n-- > 0){ String line = scanner.next(); String[] ss = line.split(":"); String s1 = toBinaryString(ss[0]); String s2 = toBinaryString(ss[1]); String s3 = toBinaryString(ss[2]); String s = s1+s2+s3; System.out.print(i++); System.out.print(" "); System.out.print(toVerticalStrgin(s)); System.out.print(" "); System.out.print(s); System.out.println(); } } static String toBinaryString(String ss){ int i = Integer.parseInt(ss); String s = Integer.toBinaryString(i); StringBuilder builder = new StringBuilder(); for(int j=s.length();j<6;j++){ builder.append("0"); } return builder.append(s).toString(); } static String toVerticalStrgin(String s){ StringBuilder builder = new StringBuilder(); for(int i=0;i<6;i++){ builder.append(s.charAt(i)); builder.append(s.charAt(6+i)); builder.append(s.charAt(12+i)); } return builder.toString(); } }
リアクション: 
poj 8462648001341607243

コメントを投稿

ホーム item

このブログを検索

Random Posts

Popular Posts

Labels

ADS