题目链接;1237: 将八进制的字符串转换成等价的十进制字符串
题目
输入八进制,输出十进制。更多内容点击标题。
分析
输入的八进制数有20位。已经超出了Integer.MAX_VALUE的范围,因此此题应该用BigInteger来处理。
测试数据
输入
55150420733754
输出
3106406643692
代码
/**
* time 1471ms
* @author PengHao
* @version A2.0
* @date 2019-04-24 下午9:12:48
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
/**
* Input
*/
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
public static void main(String[] args) {
InputReader ir = new InputReader(System.in);
String xs; // 输入的八进制字符串
BigInteger xb; // 整数
int t = ir.nextInt();
while ((t--) > 0) {
xs = ir.next();
xb = new BigInteger(xs, 8);
System.out.println(xb);
}
}
}
写在最后:
- 水题,代码随便用