题解 | DNA序列

DNA序列

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

#include <iostream>
#include <string>

using namespace std;

int main() {
    string str;
    int n;
    cin >> str >> n;
    int len = str.length();
    string res;
    double maxp = 0;   // 最大占比
    for (int i = 0; i <= len - n; ++i) {
        int cnt = 0;
        for (int j = i; j < i + n; ++j) {
            if (str[j] == 'G' || str[j] == 'C')
                cnt++;
        }
        if (maxp < (double)cnt / n) {
            res = str.substr(i, n);
            maxp = (double)cnt / n;
        }
    }

    cout << res << endl;

    return 0;
}

全部评论

相关推荐

nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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