Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HA VI N G
- HAV ING
- H AV I N G
- HAVIN G
- H AVING
- H AVIN G
- HA VING
- H AVI NG
- ....
- function f( word )
- set = word[0] + f( substring(word, 1) )
- set += word[0] + " " + f( substring(word, 1) )
- return set;
- void func(string s)
- {
- int len=s.length();
- if(len==0)
- return;
- for(int i=1;i<=len;i++)
- {
- for(int j=0;j<i;j++)
- cout<<s[j];
- cout<<" ";
- func(s[i]);
- }
- return;
- }
- public static List<List<String>> split (String str) {
- List<List<String>> res = new ArrayList<List<String>>();
- if (str == null) {
- return res;
- }
- for (int i = 0; i < str.length() - 1; i++) {
- for (List<String> list : split(str.substring(i + 1))) {
- List<String> tmpList = new ArrayList<String>();
- tmpList.add(str.substring(0, i + 1));
- for (String s : list) {
- tmpList.add(s);
- }
- res.add(tmpList);
- }
- }
- List<String> tmpList = new ArrayList<String>();
- tmpList.add(str);
- res.add(tmpList);
- return res;
- }
- public static void main(String[] args) {
- for (List<String> intermed : split("HAVING")) {
- for (String str : intermed) {
- System.out.print(str);
- System.out.print(" ");
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment