top of page
Search

USACO Guide IDE Tutorial (Walkthrough #2)

When coming into studying for USACO, I was severely uninformed and uneducated on what was necessary to even submit a USACO solution. Through research and experience, however, I have learnt what is necessary for submitting a USACO solution and am eager to share it with all of you.


The IDE that will be used most frequently in these walkthroughs will be the USACO IDE.




Upon opening the IDE, you will see the following screen. We wont be focusing on the main method or the imports today, but we will be following on the following lines and more:


The first line initializes a BufferedReader object. In this instance, the name of the object is r. BufferedReader is a java class that helps read input / text efficiently, line by line. This is important and is automatically given in the USACO IDE because USACO requires an output for their given input. It is also the reader class that is most recommended by USACO, rather than the Scanner class for instance. Within the constructor part of the declaration, the parameter new InputStreamReader(System.in) refers to the initialization of an InputStreamReader. Within the parameters for that is System.in, which is Java's way of refering to our standard keyboard keys (a, b, c, etc.). Basically, the whole line is declaring a way for us to read the given input.


The next line is similar to the last. This time we’re initializing a PrintWriter object, which is the output aspect of the code. The PrintWriter class holds common and recognizable methods such as print() and println(). The system.out aspect of the line tells the PrintWriter to output to the main console. The variable name is pw, and when using the variable in context, it will be something like pw.print();. Its more of a shortcut for output, rather than System.out.print();.


The next line utilizes the StringTokenizer class. This class cuts/splits the input based on if there is a whitespace or not. It uses one of the variables previously declared, r, which is used to read the input.


The last line is the initializing of a value into a variable. It parses the input from string (because by default the input is a string) into integer. If you want to just read the string and put the input into a string variable, you would write String a = st.nextToken();


If you want to skip a line, you would need to write st = new StringTokenizer(r.readLine());.


These are the basic ins and outs of the USACO IDE and how to take input and make output. Thank you and I look forward to solving more USACO problems with you guys.

 
 
 

Comments


bottom of page