#include <iostream>
using namespace std;
#include <string>
int main() {
string str;
int len;
getline(cin, str);
cin >> len;
int max = 0;
string maxStr;
for (int i = 0; i + len <=str.size(); i++) {
string temp = string(str.begin() + i, str.begin() + i + len);
int tempMax = 0;
for (int j = 0; j < len ; j++) {
if(temp[j] == 'C' || temp[j] == 'G'){
tempMax++;
}
}
if(tempMax > max){
maxStr = temp;
max = tempMax;
}
}
cout << maxStr << endl;
}
要注意考虑全长的情况
暴力搜索算法

京公网安备 11010502036488号