Advertisement
roronoa

ébauche moving robot

Apr 24th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. /**
  6.  * Auto-generated code below aims at helping you parse
  7.  * the standard input according to the problem statement.
  8.  **/
  9. class Solution {
  10.  
  11.     public static void main(String args[]) {
  12.         Scanner in = new Scanner(System.in);
  13.         String input = in.nextLine();
  14.         String tab[] = input.split(" ");
  15.         String res = "";
  16.         for(String x : tab)
  17.         {
  18.             if(x.equals("up"))
  19.                 res += "^ ";
  20.             else if(x.equals("right"))
  21.                 res += "> ";
  22.             else if(x.equals("down"))
  23.                 res+= "v ";
  24.             else
  25.                 res += "< ";
  26.         }
  27.         String tab2[] = res.trim().split(" ");
  28.         res = "";
  29.         int count = 1;
  30.         for(int i = 1; i < tab2.length; i++)
  31.         {
  32.            
  33.             count = 1;
  34.             while(i < tab2.length && tab2[i-1].equals(tab2[i]))
  35.             {
  36.                 count++;  
  37.                 i++;
  38.             }
  39.             res += tab2[i-1];
  40.             if(count != 1)
  41.                 res+=count;
  42.         }
  43.         if(!tab[tab.length-1].equals(tab[tab.length-2]))
  44.             //res+=tab2[tab2.length-1];
  45.         System.out.println(res.trim());
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement