Created
April 12, 2011 04:18
-
-
Save stphung/914918 to your computer and use it in GitHub Desktop.
My solution to "Your Ride Is Here" from USACO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
} | |
} |
Don't use scanner. Read the new instructions.
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!
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
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!