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

}

2 thoughts on “UVA 1124 – Celebrity Jeopardy”

  1. why it shows runtime error!!

    import java.util.Scanner;
    public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    System.out.println(sc.nextInt());
    }
    }

  2. Because the next thing might not be an integer. Scanner blocks until it gets an integer so after possibly timing out, uva probably calls it a runtime error thinking that its maybe an infinite loop in your code or something.

    I wrote nextLine() and you are writing nextInt(). Your code won’t even work for the sample test cases provided!

Leave a Reply

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