You need to take care of overflow problem.

See the code below for references.

*import java.util.ArrayList;*
*import java.util.List;*
*import java.util.Scanner;*

*public class 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<Long> lastNumbers = new ArrayList<>();*
*            long H = 0;*
*            long W = 0;*
*            long 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 += 1000000000 - mult;*
*                }*
*                else if (c == 'S') {*
*                    H += mult;*
*                }*
*                else if (c == 'W') {*
*                    W += 1000000000 - 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') {*
*                    lastNumbers.add(mult);*
*                    lastNumb = Integer.parseInt(String.valueOf(c));*
*                    mult *= lastNumb;*
*                    mult = mult % 1000000000;*
*                }*
*                else if (c == ')') {*
*                    mult = lastNumbers.remove(lastNumbers.size() - 1);*
*                }*
*                H = H % 1000000000;*
*                W = W % 1000000000;*
*            }*
*            System.out.println(String.format("Case #%s: %s %s", usease + 
1, W + 1, H + 1));*
*        }*
*    }*
*}*

-- 
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 google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/261fad91-d8c9-4976-a25a-4084f5bcd9d1%40googlegroups.com.

Reply via email to