您的位置:首页 > 其它

DNA和RNA的匹配(hdu5590)

2016-01-29 10:19 435 查看
题:Description

After getting   scores in     begins to work with biological questions.Now he give you a simple biological questions:

he gives you a   sequence and a   sequence,then he asks you whether the   sequence and the   sequence are

matched.

The   sequence is a string consisted of  ;The   sequence is a string consisted of  .

  sequence and   sequence are matched if and only if   matches  ,  matches  ,  matches  ,  matches   on each position.

 

Input

In the first line there is the testcase  .

For each teatcase:

In the first line there is one number  .

In the next line there is a string of length  ,describe the   sequence.

In the third line there is a string of length  ,describe the   sequence.

 ,

 

Output

For each testcase,print   or  ,describe whether the two arrays are matched.

 

Sample Input

2

4

ACGT

UGCA

4

ACGT

ACGU

 

Sample Output

YES

NO

解法一:

#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<math.h>

using namespace std;

int main()

{

    int t;

    char a1[200],a2[200];

    scanf("%d",&t);

    while(t--)

    {

        int n;

        int h=0;

        scanf("%d%s%s",&n,a1,a2);

        for(int i=0;i<n;i++)   //序列的长度

        {

            if(a1[i]=='A'&&a2[i]=='U')h++;   //每配对一个就加一,如果h等于n则表明全部配对

            if(a1[i]=='C'&&a2[i]=='G')h++;

            if(a1[i]=='G'&&a2[i]=='C')h++;

            if(a1[i]=='T'&&a2[i]=='A')h++;

        }

        if(h==n)printf("YES\n");

        else printf("NO\n");

    }

}

解法二:

#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<math.h>

using namespace std;

int main()

{

    int t;

    char a1[200],a2[200];

    scanf("%d",&t);

    while(t--)

    {

        int n;

        int h=0;

        scanf("%d%s%s",&n,a1,a2);

        for(int i=0;i<n;i++)   //序列的长度

        {

            if(a1[i]=='A'&&a2[i]!='U')h=1;  //有一个没配对成功就标记为一

            if(a1[i]=='C'&&a2[i]!='G')h=1;

            if(a1[i]=='G'&&a2[i]!='C')h=1;

            if(a1[i]=='T'&&a2[i]!='A')h=1;

        }

        if(h==1)printf("NO\n");

        else printf("YES\n");

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息