标签:mat eth class else AC lin tip long i++
这道题真是气死我了
一开始没看到十六进制数的长度是100000 long 保存wa了
后来大数嘛 大数超时了!!!
阿西 你100000位啊 还要逐个数位压栈保存输出呢 你还有10组测试样例 就给一秒啊你 还有java选手呢
哼 伤心
看我完美的代码
package lanqiao; import java.math.BigInteger; import java.util.Scanner; import java.util.Stack; public class basic12 { public static String c = new String(); public static Stack<BigInteger> s = new Stack<BigInteger>(); public static int t,cur; public static long cur2; public static int i; public static BigInteger sum; public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); t = in.nextInt(); c = in.nextLine(); while(t-- != 0) { sum = BigInteger.ZERO; c = in.nextLine(); for(i = 0;i < c.length();i++) { cur = (int)c.charAt(i) - ‘A‘; if(cur >= 0) { cur2 = cur + 10; sum = sum.multiply(BigInteger.valueOf(16)); sum = sum.add(BigInteger.valueOf(cur2)); } else { cur2 = (long)c.charAt(i) - ‘0‘; sum = sum.multiply(BigInteger.valueOf(16)); sum = sum.add(BigInteger.valueOf(cur2)); } } //System.out.println(sum); while(!sum.equals(BigInteger.ZERO)) { s.push((sum.mod(BigInteger.valueOf(8)))); sum = sum.divide(BigInteger.valueOf(8)); } while(!s.empty()) { System.out.print(s.peek());; s.pop(); } System.out.println(); } } }
蓝桥杯 基础 basic13 十进制转八进制(气死我了气死我了)
标签:mat eth class else AC lin tip long i++
原文地址:https://www.cnblogs.com/xuyanqd/p/9003115.html