2010年10月4日月曜日

PKU Judge Online 3617 Best Cow Line

■3617 Best Cow Line

□Problem
プログラミングコンテストチャレンジブック参照

□Solution
プログラミングコンテストチャレンジブック参照

□Code
  1. package p3617;  
  2.   
  3. import java.util.*;  
  4. import java.lang.*;  
  5. import java.math.*;  
  6. import java.io.*;  
  7.   
  8. import static java.lang.Math.*;  
  9. import static java.util.Arrays.*;  
  10.   
  11. // AC  
  12. public class Main{  
  13.   
  14.     Scanner sc=new Scanner(System.in);  
  15.   
  16.     final int INF=1<<28;  
  17.     final double EPS=1e-9;  
  18.   
  19.     void run(){  
  20.         int n=sc.nextInt();  
  21.         char[] cs=new char[n];  
  22.         for(int i=0; i<n; i++)  
  23.             cs[i]=sc.next().charAt(0);  
  24.         int l=0;  
  25.         int r=n-1;  
  26.         for(int k=1; k<=n; k++){  
  27.             boolean left=false;  
  28.             for(int i=0; l+i<=r-i; i++){  
  29.                 if(cs[l+i]<cs[r-i]){  
  30.                     left=true;  
  31.                     break;  
  32.                 }else if(cs[l+i]>cs[r-i]){  
  33.                     break;  
  34.                 }  
  35.             }  
  36.             if(left)  
  37.                 print(cs[l++]+"");  
  38.             else  
  39.                 print(cs[r--]+"");  
  40.             if(k%80==0)  
  41.                 println("");  
  42.         }  
  43.     }  
  44.   
  45.     void print(String s){  
  46.         System.out.print(s);  
  47.     }  
  48.   
  49.     void println(String s){  
  50.         System.out.println(s);  
  51.     }  
  52.   
  53.     public static void main(String[] args){  
  54.         // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));  
  55.         new Main().run();  
  56.     }  
  57. }  

0 件のコメント: