Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- unordered_map<string, int> table;
- int n, k;
- cin >> n >> k;
- string mostCommon;
- int count = 0;
- string temp;
- cin.get();
- char* input = new char[n];
- scanf("%[^\n]s", input);
- for(int i = 0; i <= n - k; i++){
- char* temp = new char[k + 1];
- strncpy(temp, &input[i], k);
- temp[k] = '\0';
- //cout << temp << endl;
- table[temp]++;
- if(table[temp] >= count){
- count = table[temp];
- mostCommon = temp;
- }
- }
- cout << mostCommon;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement