fork(1) download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/trie_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. typedef trie<
  9. string,
  10. null_type,
  11. trie_string_access_traits<>,
  12. pat_trie_tag,
  13. trie_prefix_search_node_update>
  14. pref_trie;
  15.  
  16. main()
  17. {
  18. ios::sync_with_stdio(0);
  19. cin.tie(0);
  20.  
  21. pref_trie base;
  22. base.insert("sun");
  23. string x;
  24. while(cin>>x)
  25. {
  26. if(x[0]=='?')
  27. {
  28. cout<<x.substr(1)<<endl;
  29. auto range=base.prefix_range(x.substr(1));
  30. int t=0;
  31. for(auto it=range.first;t<20 && it!=range.second;it++,t++)
  32. cout<<" "<<*it<<endl;
  33. }
  34. else
  35. base.insert(x.substr(1));
  36. }
  37.  
  38. }
  39.  
Success #stdin #stdout 0.01s 5388KB
stdin
Standard input is empty
stdout
Standard output is empty