Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class greetings {
- public static void main(String[] args) throws Exception {
- Scanner in = new Scanner(new File("greetings.in"));
- int BJour = in.nextInt();
- int EJour = in.nextInt();
- //Deal with Bessie first
- String[] BDirect = new String[BJour+1];
- int[] BCurrPosition = new int[50000];
- BCurrPosition[0] = 0;
- for(int i=1; i<=BJour; i++) { //fill in info for Bessie
- int BTime = in.nextInt(); //time unit for each fragment
- BDirect[i] = in.nextLine(); //direction for each fragment
- for(int j=1; j<=BTime; j++) {
- if(BDirect[i]=="R") { //Right is positive and Left is negative
- BCurrPosition[i] = BCurrPosition[0] + 1;
- } else if(BDirect[i]=="L") {
- BCurrPosition[i] = BCurrPosition[0] - 1;
- } else {
- BCurrPosition[i] = BCurrPosition[0] + 0;
- }
- }
- }
- //Then Elsie
- String[] EDirect = new String[BJour+1];
- int[] ECurrPosition = new int[50000];
- ECurrPosition[0] = 0;
- for(int i=1; i<=EJour; i++) { //fill in info for Elsie
- int ETime = in.nextInt(); //time unit for each fragment
- EDirect[i] = in.nextLine(); //direction for each fragment
- for(int j=1; j<=ETime; j++) {
- if(EDirect[i]=="R") { //Right is positive and Left is negative
- ECurrPosition[i] = ECurrPosition[0] + 1;
- } else if(EDirect[i]=="L") {
- ECurrPosition[i] = ECurrPosition[0] -1;
- } else {
- ECurrPosition[i] = ECurrPosition[0] + 0;
- }
- }
- }
- //Comparison
- int result = 0;
- for(int i=1; i <= 50000; i++) {
- if(BCurrPosition[i] == ECurrPosition[i]) {
- result += 1;
- }
- }
- PrintWriter out = new PrintWriter(new File("greetings.out"));
- System.out.println(result);
- out.println(result);
- in.close();
- out.close();
- }
- }
- /*
- public class greetings {
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement