zoukankan      html  css  js  c++  java
  • 一本通1131:基因相关性

    题目传送门

    【题目描述】

    为了获知基因序列在功能和结构上的相似性,经常需要将几条不同序列的DNA进行比对,以判断该比对的DNA是否具有相关性。

    现比对两条长度相同的DNA序列。定义两条DNA序列相同位置的碱基为一个碱基对,如果一个碱基对中的两个碱基相同的话,则称为相同碱基对。接着计算相同碱基对占总碱基对数量的比例,如果该比例大于等于给定阈值时则判定该两条DNA序列是相关的,否则不相关。

    【输入】

    有三行,第一行是用来判定出两条DNA序列是否相关的阈值,随后2行是两条DNA序列(长度不大于500)。

    【输出】

    若两条DNA序列相关,则输出“yes”,否则输出“no”。

    【输入样例】

    0.85
    ATCGCCGTAAGTAACGGTTTTAAATAGGCC
    ATCGCCGGAAGTAACGGTCTTAAATAGGCC

    【输出样例】

    yes

    分析:

    这个题非常简单,可以算字符串处理中的基础中的基础了
    好,开始正题。
    比对两个相不相等可以直接用str1[i]==str2[i]这条语句来判断,而循环多少次呢?
    这里主要运用到了求一个字符串长度的函数:
    有两种可供选择我一般喜欢用string的

    Sample 1:(string的函数)

    #include<string>
    len=str1.size();
    

    Sample 2:(char的函数)

    #include<cstring>
    len=strlen(str1);
    

    Code:

    #include<iostream>
    #include<cstdio>
    #include<string>
    #define rg register
    #define ll long long
    using namespace std;
    inline void read(int &x){
    	int f=1;
    	char ch=getchar();
    	x=0;
    	while(ch<'0'||ch>'9'){
    		if(ch=='-') f=-1;
    		ch=getchar();
    	}
    	while(ch>='0'&&ch<='9'){
    		x=x*10+ch-'0';
    		ch=getchar();
    	}
    	x*=f;
    }
    inline void write(int x){
    	if(x<0) putchar('-'),x=-x;
    	if(x>9) write(x/10);
    	putchar(x%10+'0');
    }
    double k;
    string str1,str2; 
    int cnt;
    int main(){
    	scanf("%lf",&k);
    	cin>>str1>>str2;
    	int len=str1.size();
    	for(int i=1;i<=len;i++){
    		if(str1[i]==str2[i]) cnt++;
    	}
    	double result=1.0*cnt/len;
    	if(result>=k) printf("yes");
    	else printf("no");
    	return 0;
    }
    
    本文欢迎转载,转载时请注明本文链接
  • 相关阅读:
    委托的例子,from C# advanced program
    C#线程通信与异步委托
    进程间通信
    线程间通信
    投影转换(AE)
    FTP多任务下载实现类
    堆内存和栈内存详解(转)
    How threads differ from processes
    实现远程FTP特定时间轨道号MODIS数据的搜索
    委托的例子
  • 原文地址:https://www.cnblogs.com/-pwl/p/13166556.html
Copyright © 2011-2022 走看看