hdoj-5590-ZYB's Biology

Problem Description
After getting 600 scores in NOIP ZYB(ZJ267) begins to work with biological questions.Now he give you a simple biological questions:
he gives you a DNA sequence and a RNA sequence,then he asks you whether the DNA sequence and the RNA sequence are
matched.

The DNA sequence is a string consisted of A,C,G,T ;The RNA sequence is a string consisted of A,C,G,U .

DNA sequence and RNA sequence are matched if and only if A matches U , T matches A , C matches G , G matches C on each position.
 

Input
In the first line there is the testcase T .

For each teatcase:

In the first line there is one number N .

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

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

1T10 , 1N100
 

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

Sample Input
   
   
   
   
2 4 ACGT UGCA 4 ACGT ACGU
 

Sample Output
   
   
   
   
YES NO
 

高中生物题,DNA和RNA的匹配

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

bool judge(char x,char y)
{
    if(x=='A'&&y=='U') return true;
    else if(x=='T'&&y=='A') return true;
    else if(x=='C'&&y=='G') return true;
    else if(x=='G'&&y=='C') return true;
    return false;
}

int main()
{
    int t;
    scanf("%d",&t);
    char d[100],r[100];
    while(t--)
    {
        int n;
        bool flag=true;
        scanf("%d",&n);
        scanf("%s",d);
        scanf("%s",r);
        //printf("%s %s\n",dna,rna);
        for(int i=0;i<n;i++)
        {
            flag=judge(d[i],r[i]);
            //printf("%d\n",flag);
            if(flag==false) break;
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}



你可能感兴趣的:(hdoj-5590-ZYB's Biology)