Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class greetings {
  5. public static void main(String[] args) throws Exception {
  6. Scanner in = new Scanner(new File("greetings.in"));
  7. int BJour = in.nextInt();
  8. int EJour = in.nextInt();
  9.  
  10. //Deal with Bessie first
  11.  
  12. String[] BDirect = new String[BJour+1];
  13. int[] BCurrPosition = new int[50000];
  14. BCurrPosition[0] = 0;
  15.  
  16. for(int i=1; i<=BJour; i++) { //fill in info for Bessie
  17. int BTime = in.nextInt(); //time unit for each fragment
  18. BDirect[i] = in.nextLine(); //direction for each fragment
  19. for(int j=1; j<=BTime; j++) {
  20. if(BDirect[i]=="R") { //Right is positive and Left is negative
  21. BCurrPosition[i] = BCurrPosition[0] + 1;
  22. } else if(BDirect[i]=="L") {
  23. BCurrPosition[i] = BCurrPosition[0] - 1;
  24. } else {
  25. BCurrPosition[i] = BCurrPosition[0] + 0;
  26. }
  27. }
  28. }
  29.  
  30. //Then Elsie
  31.  
  32. String[] EDirect = new String[BJour+1];
  33. int[] ECurrPosition = new int[50000];
  34. ECurrPosition[0] = 0;
  35.  
  36. for(int i=1; i<=EJour; i++) { //fill in info for Elsie
  37. int ETime = in.nextInt(); //time unit for each fragment
  38. EDirect[i] = in.nextLine(); //direction for each fragment
  39. for(int j=1; j<=ETime; j++) {
  40. if(EDirect[i]=="R") { //Right is positive and Left is negative
  41. ECurrPosition[i] = ECurrPosition[0] + 1;
  42. } else if(EDirect[i]=="L") {
  43. ECurrPosition[i] = ECurrPosition[0] -1;
  44. } else {
  45. ECurrPosition[i] = ECurrPosition[0] + 0;
  46. }
  47. }
  48. }
  49.  
  50. //Comparison
  51.  
  52. int result = 0;
  53. for(int i=1; i <= 50000; i++) {
  54. if(BCurrPosition[i] == ECurrPosition[i]) {
  55. result += 1;
  56. }
  57. }
  58.  
  59. PrintWriter out = new PrintWriter(new File("greetings.out"));
  60. System.out.println(result);
  61. out.println(result);
  62. in.close();
  63. out.close();
  64. }
  65. }
  66.  
  67. /*
  68.  
  69. public class greetings {
  70.  
  71. }
  72.  
  73. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement