Skip to content

Instantly share code, notes, and snippets.

@claudianus
Created November 25, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudianus/feb7d207fb320b918000792cc24c618d to your computer and use it in GitHub Desktop.
Save claudianus/feb7d207fb320b918000792cc24c618d to your computer and use it in GitHub Desktop.
c++ 문자열 정해진 길이로 쪼갠 후 갯수 새기
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(void) {
int wordLength;
string source;
map<string, int> dictionary;
cin >> wordLength;
cin >> source;
for (auto i = 0; i < source.length(); i += wordLength) {
dictionary[source.substr(i, wordLength)]++;
}
string greatest;
int seed = 0;
for (auto& x : dictionary) {
if (x.second > seed) {
greatest = x.first;
seed = x.second;
}
}
cout << greatest << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment