Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- class Solution {
- public static void main(String args[]) {
- Scanner in = new Scanner(System.in);
- String input = in.nextLine();
- String tab[] = input.split(" ");
- String res = "";
- for(String x : tab)
- {
- if(x.equals("up"))
- res += "^ ";
- else if(x.equals("right"))
- res += "> ";
- else if(x.equals("down"))
- res+= "v ";
- else
- res += "< ";
- }
- String tab2[] = res.trim().split(" ");
- res = "";
- int count = 1;
- for(int i = 1; i < tab2.length; i++)
- {
- count = 1;
- while(i < tab2.length && tab2[i-1].equals(tab2[i]))
- {
- count++;
- i++;
- }
- res += tab2[i-1];
- if(count != 1)
- res+=count;
- }
- if(!tab[tab.length-1].equals(tab[tab.length-2]))
- //res+=tab2[tab2.length-1];
- System.out.println(res.trim());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement