Dubstep

Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.

Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Polycarpus inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.

For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".

Recently, Jonny has heard Polycarpus's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Polycarpus remixed. Help Jonny restore the original song.
Input

The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters
Output

Return the words of the initial song that Polycarpus used to make a dubsteb remix. Separate the words with a space.
Examples

songDecoder("WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB")
// => WE ARE THE CHAMPIONS MY FRIEND

Good Solution1:

public class Dubstep {
  public static String SongDecoder (String song)
  {
     return song.replaceAll("(WUB)+", " ").trim();
  }
}

Good Solution2:

import java.util.Arrays;
import java.util.stream.Collectors;

public class Dubstep {
  public static String SongDecoder (String song)
  {
      return Arrays.stream(song.split("WUB"))
                   .filter(i -> !"".equals(i))
                   .collect(Collectors.joining(" "));
   }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,132评论 0 23
  • 趁着国庆七天假,去了趟嘉峪关,整整七天呆在嘉峪关,像是重新换了一个身份,领略了一下另一方水土。嘉峪关给我留下印象最...
    舞小仙7阅读 347评论 2 2
  • 走走停停,回到了原点,疲惫不堪,我的小半生就这样停在了青春之门
    wuhan寒阅读 284评论 0 0
  • 记录旅途点滴 感悟人生百味 大家好,我是“十九”,我在路上! 蓝天、白云、神秘、静谧,这大概就是西藏吧。 千山之...
    十八加一阅读 326评论 2 11
  • 你说 你个小蠢货 因为不知道哪个环节出了错 大家要在五号紧张的考期去补上那节技能实习课 你说不要说的太多 要去做 ...
    菀卿阅读 138评论 0 0