Coding_Gamesメモ_Balanced_ternary_computer_encode

Coding_Gamesメモ_Balanced_ternary_computer_encode

javaの学習にCoding_Games を知り、学習の記録としてメモ。
To debug:

System.err.println( );

を使うとデバックしやすくなる。(エラー出力は評価に影響しない)

内容

10進数→特殊3進数エンコーダー

ルール

10進数を1,0,T(-1) でできた3進数に変換する

例
8 = 1*(3^2) + 0*(3^1) + (-1)*(3^0)  
8 = 9       + 0       + (-1)  
8 = 10T  

6 = 1*(3^2) + (-1)*(3^1) + 0*(3^0)  
6 = 9       + (-3)       + 0  
6 = 1T0  

インプット

1行目 10進数 N (-30000 < N < 30000)

アウトプット

入力を変換した3進数

使用したクラス

StringBuilder

(int) = StringBuilder.length()
文字数を出力

(StringBuilder) = StringBuilder.append( x )
x はboolean,char,int,String,Objectなど
文字列の後ろにxを追加する

Math

(double) = Math.pow((double) a , (double) b)
ab a のb 乗

(long) = Math.round( (double) x )
xの四捨五入を行う
引数が(float) だと戻値が(int) になる

考え方

入力は-30000~30000の範囲なので最大でも3進数10桁(59049) 以内になる
最大桁から1桁づつ3進数に変換する

Coding_Games:https://www.codingame.com/
StringBuilder (Java Platform SE 8) - Oracle Cloud:https://docs.oracle.com/javase/jp/8/docs/api/java/lang/StringBuilder.html
Math (Java Platform SE 8) - Oracle Cloud:http://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html