Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- boolean[] sensors = new boolean[6];
- LFS state = LFS.STOP;
- String output = "";
- while (true) {
- String input = scan.nextLine();
- if (input.length() != 6) {
- break;
- }
- for (int i = 0; i < 6; i++) {
- if (input.charAt(i) == '1') {
- sensors[i] = true;
- } else {
- sensors[i] = false;
- }
- }
- switch (state) {
- case STOP:
- if (sensors[2] || sensors[3]) {
- state = LFS.FORWARD;
- }
- break;
- case FORWARD:
- if (sensors[0] || sensors[1]) {
- state = LFS.RIGHT;
- } else if (sensors[4] || sensors[5]) {
- state = LFS.LEFT;
- } else if (sensors[0] && sensors[1] && sensors[2] && sensors[3] && sensors[4] && sensors[5]) {
- state = LFS.STOP;
- }
- break;
- case RIGHT:
- if ((!sensors[0] && !sensors[1]) && (sensors[3] || sensors[4] || sensors[5])) {
- state = LFS.FORWARD;
- }
- break;
- case LEFT:
- if ((!sensors[4] && !sensors[5]) && (sensors[0] || sensors[1] || sensors[2])) {
- state = LFS.FORWARD;
- }
- break;
- }
- switch (state) {
- case STOP: System.out.println("stop"); break;
- case FORWARD: System.out.println("forward"); break;
- case RIGHT: System.out.println("right"); break;
- case LEFT: System.out.println("left"); break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement