Hello all,
I try to solve this problem but I got WA for the second test case.
As there is no new conditions between 1 and 2 I don't know why it is
happening.
Here is my code :
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Solution {
static Solution sol = new Solution();
public static void main(String[] args) {
Scanner scann = new Scanner(System.in); // Create a Scanner object
int T = Integer.parseInt(scann.nextLine());
for(int usease = 0; usease< T;usease++) {
List<Integer> lastNumbers = new ArrayList<>();
long H= 1;
long W = 1;
int mult = 1;
int lastNumb = 1;
String command = scann.next();
for(int i = 0 ; i< command.length(); i ++) {
char c = command.charAt(i);
if(c =='N') {
H -= mult;
}
else if(c =='S') {
H += mult;
}
else if(c =='W') {
W -= mult;
}
else if(c =='E') {
W += mult;
}
else if (c=='2' || c=='3' ||c=='4' ||c=='5' ||c=='6' ||c=='7' ||c=='8'
||c=='9') {
lastNumb = Integer.parseInt(String.valueOf(c));
mult *= lastNumb;
lastNumbers.add(lastNumb);
}
else if(c==')') {
mult /= lastNumbers.remove(lastNumbers.size()-1);
}
}
if(H<1) {
H = 1000000000 + H;
}
if(W<1) {
W = 1000000000 + W;
}
System.out.println(String.format("Case #%s: %s %s",usease+1,W,H));
}
}
}
Thanks for any clue.
Regard
Quentin
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/e85330db-43fa-437b-ad20-751fcd4206f0%40googlegroups.com.