51Nod 2643 基因相关性 c/c++题解

题目描述

小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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值