HDU 5590学习别人的写法

一开始使用了%c输入,导致回车也输了进去,需要用getchar先把缓冲区中的回车读完才能正常输入
一开始的写法

#include<stdio.h>
#include<iostream>
#include<algorithm>
#define MAXN_ROW 100
#define MAXN_COL 100
using namespace std;
int t;
int n;
char strDNA[101];
char strRNA[101];
int main()
{
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d", &n);
		scanf("%s", strDNA+1);
		scanf("%s", strRNA+1);
		/*
		getchar();///
		for (int i = 1; i <= n; i++)
		{
			scanf("%c", strDNA + i);
		}
		getchar();///
		for (int i = 1; i <= n; i++)
		{
			scanf("%c", strRNA + i);
		}
		*/
		int j;
		for (j = 1; j <= n; j++)
		{
			if (strDNA[j] == 'A')
			{
				if (strRNA[j] != 'U')
				{
					printf("NO\n");
					break;
				}
			}
			else if (strDNA[j] == 'T')
			{
				if (strRNA[j] != 'A')
				{
					printf("NO\n");
					break;
				}
			}
			else if (strDNA[j] == 'C')
			{
				if (strRNA[j] != 'G')
				{
					printf("NO\n");
					break;
				}
			}
			else
			{
				
				if (strRNA[j] != 'C')
				{
					printf("NO\n");
					break;
				}
			}

		}
		if (j > n)
		{
			printf("YES\n");
		}
	}
	return 0;
}

别人的
写法1:

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 105;

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

int main () {
    int cas, n;
    scanf("%d", &cas);
    while (cas--) {
        char dna[maxn], rna[maxn];
        scanf("%d%s%s", &n, dna, rna);
        bool flag = true;
        for (int i = 0; i < n; i++) flag &= judge(dna[i], rna[i]);
        printf("%s\n", flag ? "YES" : "NO");
    }
    return 0;
}

写法2:

#include<bits/stdc++.h>
using namespace std;
 
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#define ll long long
 
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
const int  maxn =5e4+5;
const int mod=1e9+7;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
char s1[105],s2[150];
int n;
map<char,char> mp;
int main()
{
    mp['A']='U',mp['T']='A',mp['C']='G',mp['G']='C';
    int t;scanf("%d",&t);
    while(t--)
    {
        int flag=1;
        scanf("%d",&n);
        scanf("%s",s1);
        scanf("%s",s2);
        for(int i=0;i<n;i++)
        {
            if( s2[i]!=mp[s1[i]] ) {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
    return 0;

写法3:

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

char s1[1500],s2[1500];

int main()
{
    int t;scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        int n;
        scanf("%d%s%s",&n,s1,s2);
        int flag = 1;
        for(int i=0;i<n;i++)
        {
            if(s1[i]=='A' && s2[i] == 'U') continue;
            if(s1[i]=='T' && s2[i] == 'A') continue;
            if(s1[i]=='C' && s2[i] == 'G') continue;
            if(s1[i]=='G' && s2[i] == 'C') continue;
            flag = 0;
            break;
        }
        if(flag==0)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

https://blog.csdn.net/keshuai19940722/article/details/50410497
https://blog.csdn.net/qq_37451344/article/details/82793444
https://www.cnblogs.com/qscqesze/p/5023314.html

上一篇:hdu 6975/ 2021“MINIEYE杯”中国大学生算法设计超级联赛(3)1003 Forgiving Matching(FFT)


下一篇:水仙花数 HDU - 2010