中油4999: Cube Bits

4999: Cube Bits

时间限制: 10 Sec   内存限制: 128 MB
提交: 151   解决: 58
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

The new computers are here! However, we made a mistake during the order: we thought we were ordering machines with qubits; in fact, we ordered several 
hundred computers powered by cube-bits. 
The programs and data we had ready were prepared in base 10. To feed the data into the new computer, which uses a cubic system of counting, we will need to convert it to base 3 first. 
Write a program to convert a stream of decimal numbers into ternary format, so they fit the new system’s input bus.

输入

The input consists of:
• One line with an integer n (1 ≤ n ≤ 106 ), the size of the data stream.
• n lines with one decimal integer v i (0 ≤ v < 320 ), the decimal representation of the i-th integer in the data stream.

输出

Output n lines, giving the numbers converted to base-3, in the same order as given. In the interest of conserving disk space, do not print leading zeroes.

样例输入

4
12
14
13
15

样例输出

110
112
111
120

提示

来源



import java.util.*;
import java.math.*;
public class Main {


public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n;
n = input.nextInt();
for(int i=0; i<n ;i++)
{
BigInteger m = input.nextBigInteger();
System.out.println(m.toString(3));
}
}


}

猜你喜欢

转载自blog.csdn.net/wonder__/article/details/79857212