fork(2) download
  1. /**
  2.  *
  3.  * @author Rohans
  4.  */
  5. public class Main {
  6.  
  7. int m(String[] a) {
  8. //declare variables for the finish the location of mario and the length
  9. int z, l = a.length - 1, m = a[0].indexOf("S");
  10. //treat the exit as a space
  11. z = a[l].indexOf("E");
  12. a[l] = a[l].replaceAll("E", " ");
  13. //go through the map
  14. for (int i = 1, x, r = 1; i <= l; i++) {
  15. //if mario can safely jump to the next platform (it picks the highest one)
  16. if (((x = a[i].indexOf("=")) != 0 && (x = a[i].indexOf(" =")) == -1) || m - x > 4) {
  17. return 0;
  18. }
  19. //adjust marios y location
  20. m = x;
  21. }
  22. //make sure mario made it to the end of the level
  23. return m == z ? 1 : 0;
  24. }
  25.  
  26. public static void MarioTest(String... testCase) {
  27. System.out.println(new Main().m(testCase) == 1 ? "Mario made it" : "Mario did not make it");
  28. }
  29.  
  30. /**
  31.   * @param args the command line arguments
  32.   */
  33. public static void main(String[] args) {
  34. MarioTest(" S=", "=====", " =", " =", "= =", " =E=");
  35. // = =
  36. // =
  37. // = =
  38. // S= E
  39. // ======
  40.  
  41. }
  42.  
  43. }
Success #stdin #stdout 0.1s 321600KB
stdin
Standard input is empty
stdout
Mario did not make it