ACM JAVA大数
有的水題自己模擬下大數就過了,有的各種坑,天知道曾經因為大數wa了多少次....自己最近學者用JAVA,下面是自己總結的JAVA常用知識..
框架
import java.util.Scanner;
import java.math.*;
public class Main
{
? ?public static void main(String args[])
? ?{
? ? }
}
輸入輸出
Scanner cin = new Scanner(System.in);
int t = cin.nextInt(); ?//輸入 int t
BigInteger m = cin.nextBigInteger();//輸入 bigint m?
(實數是BigDecimal)
String s; s = cin.next();//串char op = s.charAt(0);
System.out.println();輸出
類型轉換
BigInteger tmp=BigInteger.valueOf(n);//整數
BigDecimal tmp=BigDecimal.valueOf(n);//實數
s = a.toString();//字符串
基本函數
1.valueOf(parament); 將參數轉換為制定的類型 ?
2.add(); 大整數相加
3.subtract(); 相減
4.multiply(); 相乘
5.divide(); ? ?相除取整
6.remainder();取余
7.pow(); ? a.pow(b)=a^b
8.gcd(); ? 最大公約數
9.abs(); 絕對值
10.negate();取反數
11.mod(); a.mod(b)=a%b=a.remainder(b);
12.max(); min();
13.punlic int comareTo();
14.boolean equals(); 是否相等
基本常量
A=BigInteger.ONE ? ?1
B=BigInteger.TEN ? ?10
C=BigInteger.ZERO ? 0
總結
以上是生活随笔為你收集整理的ACM JAVA大数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu1261 JAVA
- 下一篇: hdu2489-DFS+最小生成树