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; | |
} | |
} |
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
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!