Guest User

Untitled

a guest
May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string temp,s,operation;
  4. int n;
  5. map<string,int> m;
  6. /*Put all possible prefix into map, then output the number of prefix in the map*/
  7. int main(){
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10. cin>>n;
  11. for (int i=0; i<n; i++){
  12. cin>>operation;
  13. if (operation == "add"){
  14. cin>>s;
  15. temp.clear();
  16. for (int j=0; j<s.length(); j++){
  17. temp+=s[j];
  18. m[temp]++;
  19. }
  20. } else{
  21. cin>>s;
  22. cout<<m[s]<<'\n';
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment