Created
November 25, 2018 15:02
-
-
Save claudianus/feb7d207fb320b918000792cc24c618d to your computer and use it in GitHub Desktop.
c++ 문자열 정해진 길이로 쪼갠 후 갯수 새기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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