gravatar

T1072-虚假的答案:真实的答案

Joey20191113114 at 2020-02-08T10:01:58+00:00 Go TO Problem T1072

<!--Markdown--> 虚假:(写了好久测试也没问题就是不AC的代码) import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); String decimal=in.nextLine(); BigInteger n=new BigInteger(decimal); String hexStr=""; BigInteger baseCode=new BigInteger("16"); BigInteger zero=new BigInteger("0"); while(!n.equals(zero)) { String hexDigitStr=n.remainder(baseCode)+""; long hexDigit=Integer.parseInt(hexDigitStr); char hexDigitCh=(hexDigit<=9&&hexDigit>=0)?(char)(hexDigit+'0'):(char)(hexDigit-10+'A'); hexStr=hexDigitCh+hexStr; n=n.divide(baseCode); } System.out.print(hexStr); in.close(); } } 真实:(从网上扒的只有11行而且超简单秒AC的代码) import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String num = in.nextLine(); BigInteger step = new BigInteger(num); System.out.println(step.toString(16).toUpperCase()); in.close(); } } 感觉自己可能不太适合学java ( ̄┰ ̄*)ゞ

Comments:

No comment yet.