結果
問題 |
No.782 マイナス進数
|
ユーザー |
![]() |
提出日時 | 2019-12-25 13:54:28 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,017 bytes |
コンパイル時間 | 3,208 ms |
コンパイル使用メモリ | 74,924 KB |
実行使用メモリ | 58,296 KB |
最終ジャッジ日時 | 2024-09-25 00:07:27 |
合計ジャッジ時間 | 13,660 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 WA * 9 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int b = - sc.nextInt(); StringBuilder ans = new StringBuilder(); for (int i = 0; i < t; i++) { boolean isPlus = true; int x = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (x > 0) { if (isPlus) { sb.append(x % b); x /= b; isPlus = false; } else { if (x % b == 0) { sb.append(0); x /= b; } else { sb.append(b - x % b); x /= b; x++; } isPlus = true; } } ans.append(sb.reverse()).append("\n"); } System.out.print(ans); } }