JAVA ACMの使用

5818 ワード

7. POJ       :
POJ 1131 1205 1220 1405 1503 1604 1894 2084 2305 2325 2389 2413 3101 3199


/*czyuan    ,        */


 1.入出力の使用、直接コードを見る
 
package endual;


import java.math.*;
import java.util.*;


public class ComputApp
{
    public static void main(String[] args) 
    {
    	
   
    	//       
        Scanner cin = new Scanner (System.in);
        int a; 
        double b; 
        String st;
        
        a = cin.nextInt(); //    , Anter   ,   a
        b = cin.nextDouble(); //    , Anter   ,   b
        st = cin.next() ; ////    , Anter   ,   st
        
        //    ,             
        //Scanner        ,       。          ,         :
        //int ---->>nextInt() ;
        //String --->>next() ;
        //                   。
        
        
        
    	//       
        //         System.out.println()    
        //System.out.print()     
        System.out.println(a);
        System.out.println(b);
        System.out.println(st);
       
    }
}

 
 
2.出力の特別説明
2.   
  :System.out.print(); System.out.println(); System.out.printf();
System.out.print(); // cout << …;
System.out.println(); // cout << … << endl;
System.out.printf(); //  C  printf    .

  :
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
", a, b); // b 10, , 5 , . } }

 
 
 
      :
  :
//   0     ,#  0     (   0,    ),    .
    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.      
java    String       ,            .

  :
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)    st[i].
        char [] ch;
        ch = st.toCharArray(); //           .
        for (i = 0; i < ch.length; i++) ch[i] += 1;
        System.out.println(ch); //    “bcdefgh”.
if (st.startsWith("a")) //       '0'  .
        {
            st = st.substring(1); //    1   copy(    0 ).
        }
    }
}

 
 
 
4.    
BigInteger BigDecimal    acmer  java     。
  :add, subtract, divide, mod, compareTo ,           BigInteger(BigDecimal) BigInteger(BigDecimal)     ,     int(double)     BigInteger(BigDecimal),   BigInteger.valueOf().

  :
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.     
java        。
  :
String st = Integer.toString(num, base); //  num  10      base   st(base <= 35).
int num = Integer.parseInt(st, base); //  st  base  ,  10   int(parseInt     ,          ,           ).   
BigInter m = new BigInteger(st, base); // st    ,base st   .




 
 
6.   
  :Arrays.sort();         , C++   cmp   , java     ,       ~~

  :
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] + " ");
    }
}