import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { BigInteger s = in.nextBigInteger(); String str = s.toString(2); System.out.println(str); } in.close(); } }
Java大整数API
import java.util.Scanner; import java.math.BigInteger; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String num = in.next(); BigInteger b = new BigInteger(num); System.out.println(b.toString(2)); } } }
import java.util.Scanner; import java.math.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String a = in.nextLine(); System.out.println(new BigInteger(a).toString(2)); } } }
import java.util.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin=new Scanner(System.in); while(cin.hasNext()){ BigInteger s=cin.nextBigInteger(); String ans=s.toString(2); System.out.println(ans); } } }
import java.util.*; import java.math.BigInteger; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); while (in.hasNext()){ String str=in.nextLine(); BigInteger a=new BigInteger(str,10); System.out.println(a.toString(2)); } }
import java.math.BigInteger; import java.util.Scanner; /** * Created by fhqplzj on 17-2-1 at 下午1:35. */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int m = scanner.nextInt(); int n = scanner.nextInt(); String x = scanner.next(); System.out.println(new BigInteger(x, m).toString(n)); } } }
} 做这道题的时候,一开始用int型数据类型,总是测试不通过,这是没有按照要求做题, 注意题目需要大数据,然后该成BigInteger类型后,所有的数据均测试成功。