华为oj初级 DNA序列
2017-03-09 20:55
363 查看
描述
一个DNA序列由A/C/G/T四个字母的排列组合组成。G和C的比例(定义为GC-Ratio)是序列中G和C两个字母的总的出现次数除以总的字母数目(也就是序列长度)。在基因工程中,这个比例非常重要。因为高的GC-Ratio可能是基因的起始点。
给定一个很长的DNA序列,以及要求的最小子序列长度,研究人员经常会需要在其中找出GC-Ratio最高的子序列。
知识点 字符串
运行时间限制 10M
内存限制 128
输入
输入一个string型基因序列,和int型子串的长度
输出
找出GC比例最高的字串
样例输入 AACTGTGCACGACCTGA 5
样例输出 GCACG
一个DNA序列由A/C/G/T四个字母的排列组合组成。G和C的比例(定义为GC-Ratio)是序列中G和C两个字母的总的出现次数除以总的字母数目(也就是序列长度)。在基因工程中,这个比例非常重要。因为高的GC-Ratio可能是基因的起始点。
给定一个很长的DNA序列,以及要求的最小子序列长度,研究人员经常会需要在其中找出GC-Ratio最高的子序列。
知识点 字符串
运行时间限制 10M
内存限制 128
输入
输入一个string型基因序列,和int型子串的长度
输出
找出GC比例最高的字串
样例输入 AACTGTGCACGACCTGA 5
样例输出 GCACG
#include <iostream> #include<vector> #include<algorithm> #include<string> using namespace std; int main(){ string s; getline(cin, s); int Len; cin >> Len; int index; int num_GC; int max = 0; string str; for (int i = 0; i <=s.size() - Len; i++){ str = s.substr(i, Len); num_GC = count(str.begin(), str.end(), 'G') + count(str.begin(), str.end(), 'C'); if (num_GC > max){ max = num_GC; index = i; } } cout << s.substr(index, Len) << endl; return 0; }
相关文章推荐
- 华为OJ 初级:DNA序列
- 华为OJ(DNA序列)
- DNA序列——来自华为OJ平台测试的基础题
- [华为OJ--C++]089-DNA序列
- 华为OJ DNA序列 Java
- 华为OJ:DNA序列
- 华为OJ:DNA序列
- 华为OJ——DNA序列
- 华为oj题目 DNA序列 [java语言]
- 【华为OJ】DNA序列
- 华为OJ训练之0012-170101-DNA序列
- 华为oj DNA序列
- 华为OJ平台——DNA序列
- 【华为OJ】【089-DNA序列】
- 华为oj DNA序列
- OJ平台——DNA序列
- 华为oj 初级 输出单向链表中倒数第k个结点
- 华为OJ之初级篇Ⅰ
- 华为oj初级 字符串通配符
- 华为oj初级 201301 JAVA题目0-1级