题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
#include <iostream>
#include <string>
#include<map>
using namespace std;
int main()
{
string s1,s2;
map<int, int> map1;
int n;
int max1 = 0;
while(cin>>s1>>n)
{
int arr[s1.size()];
for(int i=0;i<s1.size()-n+1;i++)
{
int count = 0;
s2 = s1.substr(i, n);
for(int j=0;j<s2.size();j++)
{
if(s2[j]=='C'||s2[j]=='G')
{
count++;
}
}
arr[i]=count;
max1 = max1>count?max1:count;
}
for(int i=0;i<s1.size();i++)
if(arr[i]==max1)
{
cout<<s1.substr(i,n)<<endl;
break;
}
}
return 0;
}