题解 | #DNA序列#简单解法,遍历即可

DNA序列

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

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

int main()
{
    string str;
    int num;
    
    while (cin >> str >> num) {
        string s;
        string subs; //保存最大值对应的字串
        int max = 0; // 最大值
        for (int i = 0;i < str.size();i++) {
            int cnt = 0; // 记录当前长度
            s = str.substr(i, num); // 子串
            for (auto const &c : s) {
                if (('C' == c) || ('G' == c)) cnt++;
            }
            if (cnt > max) {
                max = cnt;
                subs = s;
            }
        }
        cout << subs << endl;
    }
    
    return 0;
}
全部评论

相关推荐

xxxxOxo:这公司幽默得很,要了简历半天一点动静都没有,过一会就给你发个邮件让你做测试,做完又没后文了,纯溜人
点赞 评论 收藏
分享
01-07 15:50
四川大学 Java
看日出看日落:好好背八股,做算法。我身边跟你bg差不多的基本都大厂暑期
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务