Skip to content

Instantly share code, notes, and snippets.

@stphung
Created April 12, 2011 04:18
Show Gist options
  • Save stphung/914918 to your computer and use it in GitHub Desktop.
Save stphung/914918 to your computer and use it in GitHub Desktop.
My solution to "Your Ride Is Here" from USACO
/*
ID: stphung1
LANG: JAVA
TASK: ride
*/
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
class ride {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new File("ride.in"));
PrintWriter pw = new PrintWriter(new File("ride.out"));
if (toNumber(sc.nextLine()) % 47 == toNumber(sc.nextLine()) % 47) {
pw.println("GO");
} else {
pw.println("STAY");
}
pw.close();
}
public static int toNumber(String name) {
int product = 1;
for (int i = 0; i < name.length(); i++) {
int charVal = (name.charAt(i) - 'A') + 1;
product *= charVal;
}
return product;
}
}
@Tiffastic
Copy link

Thank you so much for showing me how to use Scanner and PrintWriter. I was able to submit my work now that I see how you used Scanner and PrintWriter to read in and print out the information. Thank you. I wish USACO gave more examples on these read-in and print-out topics in order to help new programmers submit their
work successfully.

Again, thank you!

@cycfunc
Copy link

cycfunc commented Jun 18, 2017

Don't use scanner. Read the new instructions.

@krowter
Copy link

krowter commented Feb 2, 2019

Thankyou!
Actually I'm using c++, but I thought we only need to print GO or STAY until I saw your code that we actually have to create a file "ride.out". Thanks again!

@osly888
Copy link

osly888 commented Feb 18, 2019

thanks so much for showing me the way to successfully turn in my java code. love ya man no homo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment