题解 | #DNA序列#

DNA序列

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

//暴力的代码
//主要想吐槽一下题目里说的“DNA序列为 ACGT 的子串有: ACG , CG , CGT 等等,但是没有 AGT , CT 等等
//我判断了半天没有AGT、CT、ACT等等情况,难怪一个用例都过不了...

#include <iostream>
#include <string>
using namespace std;

int main() {
    string inputstr;
    cin >> inputstr;
    int len;
    cin >> len;
    double maxratio = 0;
    string res;
    for(int i = 0;i<=inputstr.size()-len;++i){
        double countCG = 0.0;
        string strtmp;
        for(int j = i;j<i+len;++j){
            strtmp += inputstr[j];
            if(inputstr[j] == 'C' || inputstr[j] == 'G')++countCG;
        }
        if(strtmp.size() == len && (countCG/len > maxratio)){
            maxratio = countCG/len;
            res = strtmp;
        }
    }
    cout << res << endl;
    return 0;
}
全部评论

相关推荐

牛客48826091...:哥们胸肌挺好看
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务