题解 | DNA序列

#include <algorithm>

#include <climits>

#include <iostream>

#include <vector>

using namespace std;

int main() {

    string s;

    int n;

    cin >> s >> n;

    vector<string> subs;

    vector<double> res;

    double max = INT_MIN;

    for (int i = 0; i < s.length() - n + 1; i++) {

        string str;

        str = s.substr(i, n);

        int count = 0;

        for (int j = 0; j < str.length(); j++) {

            if (str[j] == 'G' || str[j] == 'C') {

                count++;

            }

        }

        res.push_back((double)count / (double)str.length());  //把所有子串和比例都放进去

        subs.push_back(str);

    }

    for (double x : res) { //找到最大值

        if(x>max)  max = x;

    }

    int j=-1;

    for (int i=0; i<res.size(); i++) { //找到最大值的下标位置

        if(res[i] == max) {

            j=i;

            break;

        }

    }

    cout<<subs[j]; //按照对应关系输出子串

}

// 64 位输出请用 printf("%lld")

全部评论

相关推荐

01-14 16:23
广州商学院 Java
点赞 评论 收藏
分享
做黑夜里的那道光:两年电赛完赛没必要写,纯扣分
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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