Last active
August 29, 2015 13:56
-
-
Save KT-Yeh/9251367 to your computer and use it in GitHub Desktop.
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() | |
| { | |
| ios::sync_with_stdio(false); | |
| int N; | |
| string str; | |
| while (cin >> N) { | |
| cin.get(); | |
| getline(cin, str); | |
| map<string, int> Map; | |
| for (int i = 0; i <= str.size()-N; ++i) { | |
| string tmp = str.substr(i, N); // 從第i個位置擷取str N個字元 | |
| if (!Map[tmp]) Map[tmp] = 1; | |
| else Map[tmp]++; | |
| } | |
| int Max = 0; | |
| for (auto &m : Map) { // m為pair structure | |
| if (m.second > Max) { | |
| Max = m.second; | |
| str = m.first; | |
| } | |
| } | |
| cout << str << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment