题解 | #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;
}
全部评论

相关推荐

自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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