package chapter2.beginner.example10;

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by jsong on 12/04/2017.
 *
 * @hackerrank https://www.hackerrank.com/jsong00505
 * @backjoon https://www.acmicpc.net/user/jsong00505
 * @github https://github.com/jsong00505
 * @linkedin https://www.linkedin.com/in/junesongskorea/
 * @email jsong00505@gmail.com
 * @challenge Best Cow Line(POJ 3617)
 */
public class Solution {
  /**
   * get a best cow line
   *
   * @param s
   * @return a best cow line
   */
  static char[] getBestCowLine(String s) {
    char[] t = new char[s.length()];
    int start = 0;
    int end = s.length() - 1;

    for (int i = 0; i < t.length; i++) {
      if(s.charAt(start) < s.charAt(end)) {
        t[i] = s.charAt(start++);
      } else {
        t[i] = s.charAt(end--);
      }
    }

    return t;
  }

  public static void main(String[] args) {
    try(Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);) {
      int n = in.nextInt();

      // constraints
      assert(n >= 1 && n <= 2000);

      String s = in.next();

      // constraints
      assert(n == s.length());

      // print
      out.println(getBestCowLine(s));
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}

@@ -693,16 +693,17 @@
       if
+ 
 (s.charA
@@ -726,24 +726,24 @@
 rAt(end)) %7B%0A
-
         t%5Bi%5D
@@ -895,16 +895,17 @@
 %0A    try
+ 
 (Scanner
@@ -988,16 +988,17 @@
 em.out);
+ 
 ) %7B%0A    
@@ -1055,16 +1055,17 @@
   assert
+ 
 (n %3E= 1 
@@ -1142,16 +1142,17 @@
   assert
+ 
 (n == s.
@@ -1216,16 +1216,16 @@
 ne(s));%0A
-
     %7D ca
@@ -1227,16 +1227,17 @@
  %7D catch
+ 
 (Excepti

reformat java google coding style