题解 | #DNA序列#

DNA序列

https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a

#include <bits/stdc++.h>
using namespace std;

int main() {
    string str;
    int n;
    getline(cin, str);
    //cin.get();
    cin >> n;
    int len=0;
    double ratio;
    ratio = len/n;
    int temp = 0;
    string word = "";
    string word_temp = "";
    if(n<str.size()){
	  for(int i=0; i<str.size()-n; i++){
		  temp = 0;
		  word_temp = "";
		  for(int j=0; j<n; j++){
			  if(str[i+j] == 'G') temp += 1;
			  else if(str[i+j] == 'C') temp += 1;
			  word_temp += str[i+j];
		  }
		  if(temp>len){
			  len = temp;
			  word = word_temp;
		  }
	  }
    }
    else word = str;
    cout << word;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务