Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. int main() {
  2. unordered_map<string, int> table;
  3.  
  4. int n, k;
  5. cin >> n >> k;
  6.  
  7. string mostCommon;
  8. int count = 0;
  9. string temp;
  10.  
  11. cin.get();
  12. char* input = new char[n];
  13.  
  14. scanf("%[^\n]s", input);
  15. for(int i = 0; i <= n - k; i++){
  16. char* temp = new char[k + 1];
  17. strncpy(temp, &input[i], k);
  18. temp[k] = '\0';
  19. //cout << temp << endl;
  20.  
  21. table[temp]++;
  22. if(table[temp] >= count){
  23. count = table[temp];
  24. mostCommon = temp;
  25. }
  26. }
  27. cout << mostCommon;
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement