题解 | #DNA序列#

DNA序列

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

#include <iostream>
using namespace std;
#include <string>
int main() {
    string str;
    int len;
    getline(cin, str);
    cin >> len;
    int max = 0;
    string maxStr;
    for (int i = 0; i + len <=str.size(); i++) {
        string temp = string(str.begin() + i, str.begin() + i + len);
        int tempMax = 0;
        for (int j = 0; j < len ; j++) {
            if(temp[j] == 'C' || temp[j] == 'G'){
                tempMax++;
            }
        }
        if(tempMax > max){
            maxStr = temp;
            max = tempMax;
        }
    }
    cout << maxStr << endl;
}

要注意考虑全长的情况

暴力搜索算法

华为机试刷题记录 文章被收录于专栏

记录一下手打代码的解题思路方便复习

全部评论

相关推荐

10-31 20:07
门头沟学院 Java
点赞 评论 收藏
分享
程序员牛肉:你这其实一点都没包装,标准的流水线产品。 实习现在不一定能解决你的问题,你太浮躁了。你看了多少源码?看了多少技术博客?真的没必要这么浮躁的着急找实习,沉下心来学习
投递实习岗位前的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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