Tag Archives: uva online judge

UVA 1124 – Celebrity Jeopardy

Just re-print the input. There has to be a cooler way to do this in Java. I really want to just pipe the inputstream to the outputstream somehow.

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

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

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    while (sc.hasNextLine()) {
      out.println(sc.nextLine());
    }
    out.close();
    sc.close();
  }

}

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();
  }

}

Competitive Programming 3

So I finally shelled out $40 and bought this book, I’ve been wanting to buy it for a while so I went all out and bought the hardcover. Books pretty well written and a definite improvement over the first edition. The first edition is free now by the way; you can either donate to lulu and get it or you can just download it for free. You’ll still learn a lot from the first edition so I recommend that people read up on that if they can’t afford to buy this most recent edition.

Competitive Programming 3
Competitive Programming 3

The questions mentioned in the book are available on the UVA Online Judge so if you just want to practice they are all there. However, you will seriously miss out on all the insights and tips that the authors share. I highly recommend that people buy the book if they want to get better like I do. I’m giong to be going through every single question in this book and see how it effects my ranking on Codeforces and Topcoder. I’ll be posting solutions to all the UVA Questions mentioned in the book in case anyone is interested. The link for the free first edition can be found on the authors booksite :)

My solutions to the questions in the book are listed in the “Competitive Programming 3” page over on the right side of this page.