Guest User

Untitled

a guest
Jul 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. HA VI N G
  2. HAV ING
  3. H AV I N G
  4. HAVIN G
  5. H AVING
  6. H AVIN G
  7. HA VING
  8. H AVI NG
  9.  
  10. ....
  11.  
  12. function f( word )
  13. set = word[0] + f( substring(word, 1) )
  14. set += word[0] + " " + f( substring(word, 1) )
  15. return set;
  16.  
  17. void func(string s)
  18. {
  19. int len=s.length();
  20. if(len==0)
  21. return;
  22. for(int i=1;i<=len;i++)
  23. {
  24. for(int j=0;j<i;j++)
  25. cout<<s[j];
  26. cout<<" ";
  27. func(s[i]);
  28. }
  29. return;
  30. }
  31.  
  32. public static List<List<String>> split (String str) {
  33. List<List<String>> res = new ArrayList<List<String>>();
  34. if (str == null) {
  35. return res;
  36. }
  37. for (int i = 0; i < str.length() - 1; i++) {
  38. for (List<String> list : split(str.substring(i + 1))) {
  39. List<String> tmpList = new ArrayList<String>();
  40. tmpList.add(str.substring(0, i + 1));
  41. for (String s : list) {
  42. tmpList.add(s);
  43. }
  44. res.add(tmpList);
  45. }
  46. }
  47. List<String> tmpList = new ArrayList<String>();
  48. tmpList.add(str);
  49. res.add(tmpList);
  50. return res;
  51. }
  52.  
  53. public static void main(String[] args) {
  54. for (List<String> intermed : split("HAVING")) {
  55. for (String str : intermed) {
  56. System.out.print(str);
  57. System.out.print(" ");
  58. }
  59. System.out.println();
  60. }
  61. }
Add Comment
Please, Sign In to add comment