Thursday, September 6, 2012

an url can contain words

an url can contain words. For instance akillernewappforwork.com. Device an algorithm for extracting all the words from an url

1 comment:

  1. Nice problem!

    Set dict = new HashSet();
    dict.add("coding");
    dict.add("play");
    dict.add("ground");
    dict.add("playground");
    dict.add("blog");
    dict.add("spot");

    String url = "codingplayground.blogspot.com";
    List list = new ArrayList();
    List tmp = new ArrayList();
    for(int i = 0; i < url.length(); i++) {
    char ch = url.charAt(i);
    tmp.clear();
    if (dict.contains("" + ch)) System.out.println(ch);
    for(String prev : list) {
    String word = prev + ch;
    if (dict.contains(word)) System.out.println(word);
    tmp.add(word);
    }
    list.clear();
    list.addAll(tmp);
    list.add("" + ch);
    }
    }

    ReplyDelete