This Java crash, which is limited to Java syntax, includes input and output, arithmetic processing, string and high-precision processing, conversion between systems, and can solve some of the high precision problems on OJ.
1. Input:
The format is: Scanner cin = new Scanner (new Bufferedinputstream (system.in));
Routines:
Import java.io.*;
Import java.math.*;
Import java.util.*;
Import java.text.*;
public class Main
{
public static void Main (string[] args)
{
Scanner cin = new Scanner (new Bufferedinputstream (system.in));
int A; Double b; BigInteger C; String St;
A = Cin.nextint (); b = cin.nextdouble (); c = Cin.nextbiginteger (); D = Cin.nextline (); Each type has a corresponding input function.
}
}
2. Output
Function: System.out.print (); System.out.println (); System.out.printf ();
System.out.print (); cout << ...;
System.out.println (); cout << ... << Endl;
System.out.printf (); Similar to the printf usage in C.
Routines:
Import java.io.*;
Import java.math.*;
Import java.util.*;
Import java.text.*;
public class Main
{
public static void Main (string[] args)
{
Scanner cin = new Scanner (new Bufferedinputstream (system.in));
int A; Double b;
A = 12345; b = 1.234567;
System.out.println (A + "" + B);
System.out.printf ("%d%10.5f\n", A, b); Enter B for the word width of 10, right aligned, keep 5 digits after the decimal point, rounded.
}
}
Normalized output:
Function:
Here 0 refers to a digit, #指除0以外的数字 (if 0 is not shown), rounded.
DecimalFormat fd = new DecimalFormat ("#.00#");
DecimalFormat gd = new DecimalFormat ("0.000");
System.out.println ("x =" + Fd.format (x));
System.out.println ("x =" + Gd.format (x));
3. String processing
String strings in Java are not modifiable, and modifications can only be converted to character arrays.
Routines:
Import java.io.*;
Import java.math.*;
Import java.util.*;
Import java.text.*;
public class Main
{
public static void Main (string[] args)
{
int i;
Scanner cin = new Scanner (new Bufferedinputstream (system.in));
String st = "ABCDEFG";
System.out.println (St.charat (0)); St.charat (i) is equivalent to St[i].
char [] ch;
ch = st.tochararray (); The string is converted to a character array.
for (i = 0; i < ch.length i++) Ch[i] + = 1;
SYSTEM.OUT.PRINTLN (CH); Enter as "BCDEFGH".
if (St.startswith ("a"))//If the string starts with ' 0 '.
{
st = st.substring (1); The copy begins at the 1th bit (the beginning is the No. 0 bit).
}
}
}
4. High precision
BigInteger and BigDecimal can be said to be the primary reason for Acmer to choose Java.
Functions: Add, subtract, divide, mod, CompareTo, etc., where the subtraction module requires an operation between BigInteger (BigDecimal) and BigInteger (BigDecimal), so an int ( Double) type to BigInteger (BigDecimal), with function biginteger.valueof ().
Routines:
Import java.io.*;
Import java.math.*;
Import java.util.*;
Import java.text.*;
Public class Main
{
public static void Main (string[] args)
{ Scanner cin = new Scanner (new Bufferedinputstream (system.in));
int a = 123, B = 456, c = 7890;
BigInteger x, y, z, ans;
x = biginteger.valueof (a); y = biginteger.valueof (b); z = Biginteger.valueof (c);
ans = x.add (y); System.out.println (ANS);
ans = z.divide (y); System.out.println (ANS);
ans = X.mod (z); System.out.println (ANS);
if (ans.compareto (x) = = 0) System.out.println ("1");
}
}
5. In-Process conversion
Java is a powerful feature.
Function:
String st = integer.tostring (num, base); Convert num to the base <= 35 as the number of 10.
int num = Integer.parseint (st, base); Take St as base, turn to 10 int (parseint has two parameters, the first is the string to be turned, and the second is the description of what the system is).
Biginter m = new BigInteger (St, base); St is a string, base is St's system.
6. Sorting
Function: Arrays.sort (), as to how to sort the structure, like C + + to write a CMP method, in Java is not very clear, I hope someone to guide ~ ~
Routines:
Import java.io.*;
Import java.math.*;
Import java.util.*;
Import java.text.*;
public class Main
{
public static void Main (string[] args)
{
Scanner cin = new Scanner (new Bufferedinputstream (system.in));
int n = cin.nextint ();
int a[] = new int [n];
for (int i = 0; i < n; i++) A[i] = Cin.nextint ();
Arrays.sort (a);
for (int i = 0; i < n; i++) System.out.print (A[i] + "");
}
}
7. POJ High Accuracy Topic Summary:
POJ 1131 1205 1220 1405 1503 1604 1894 2084 2305 2325 2389 2413 3101-3199
Turn from: http://hi.baidu.com/czyuan_acm/item/2c115f6b3d35192469105bae