fork download
  1. #include <set>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include<string.h>
  7. #define MAX 12
  8. using namespace std;
  9. string arr[]={"i", "like", "sam", "sung", "samsung", "mobile", "ice","cream", "icecream", "man", "go", "mango"};
  10. set<string> dictionary (arr,arr+MAX);
  11. int cnt=0;
  12.  
  13. void search_grow(string str, int i, int j)
  14. {
  15. if(i > j || j >= str.length() || i >= str.length())
  16. {
  17. return;
  18. }
  19.  
  20. string temp(str, i, j - i + 1);
  21. if(dictionary.find(temp) != dictionary.end())
  22. {
  23. std::cout << "[search_grow] " << temp << "\n";
  24. cnt++;
  25. }
  26. search_grow(str, i, j + 1);
  27. }
  28.  
  29. void search_part(string str)
  30. {
  31. for(int t = 0; t < str.size(); t++)
  32. search_grow(str, t, t);
  33. }
  34.  
  35. int main()
  36. {
  37. string str;
  38. cin>>str;
  39. search_part(str);
  40. cout<<cnt<<endl;
  41. return 0;
  42. }
Success #stdin #stdout 0s 3436KB
stdin
icecreamicecream
stdout
[search_grow] i
[search_grow] ice
[search_grow] icecream
[search_grow] cream
[search_grow] i
[search_grow] ice
[search_grow] icecream
[search_grow] cream
8