题目描述

小Z是一个生物研究员,现在在研究基因序列在功能和结构上的相似性,经常需要将几条不同序列的DNA进行比对,以判断该对DNA是否具有相关性。
现对比两条长度相同的DNA序列,有以下规则:
①定义两条DNA序列相同位置的碱基为一个碱基对,如果一个碱基对中的两个碱基相同的话,则称为相同碱基对。
②计算相同碱基对占总碱基对数量的比例,如果该比例大于等于给定阈值时则判定该两条DNA序列是相关的,否则不相关。
(DNA的碱基只有ACGT,大写字母表示)
输入
第一行 一个阈值p(两位小数,用来判断两条DNA是否相关)
接下来两行 每行一个字符串表示DNA序列(长度不大于5000)
输出
若两条DNA序列相关,则输出"yes",否则输出"no"
输入样例
0.25
CTTG
GACC
输出样例
no

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <iterator>
using namespace std;

typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll  INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int MOD = 1e9+7;
const int MAX = 1e5+5;
double p;
string DNA1,DNA2;

int main()
{
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    */

    while(cin >> p)
    {
        cin >> DNA1 >> DNA2;
        int len = DNA1.length();
        int sum = 0;
        for(int i = 0; i < len; i++)
        {
            if(DNA1[i] == DNA2[i])
                sum++;
        }
        if((1.0*sum)/len >= p)
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }

    return 0;
}
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐