UVA 272 – TEX Quotes

This problem is super easy beacuse we are guaranteed that every quote is there an even number of times. Just replace the odd and even quotes in a different manner and you are set!

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

/**
 * 
 * @author Sanchit M. Bhatnagar
 * @see http://uhunt.felix-halim.net/id/74004
 * 
 */
public class P272 {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    boolean even = true;
    while (sc.hasNextLine()) {
      char[] line = sc.nextLine().toCharArray();
      for (Character c : line) {
        if (c == '"') {
          if (even) {
            out.print("``");
          } else {
            out.print("''");
          }
          even = !even;
        } else {
          out.print(c);
        }
      }
      out.print(System.lineSeparator());
    }
    out.close();
    sc.close();
  }

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.