蓝桥杯试题——基因配对
#include<iostream>
#include<cstring>
using namespace std;
char L[1000000];
char S[1000000];
int len1;
int len2;
int Compare(int n){
int j=0;
for(int i=n;i<len1;i++){
if(L[i]!=S[j])
return 0;
else if(L[i]==S[j]&&j<len2-1){
j++;
}
else if(L[i]==S[j]&&j==len2-1){
return 1;
}
}
}
int main() {
int flag,i;
gets(L);
gets(S);
len1=strlen(L);
len2=strlen(S);
for(int i=0;i<len2;i++){
if(S[i]=='A')
S[i]='T';
else if(S[i]=='T')
S[i]='A';
else if(S[i]=='C')
S[i]='G';
else if(S[i]=='G')
S[i]='C';
}
for (i=0;i<len1-len2;i++){
flag=0;
if(L[i]==S[0]){
flag = Compare(i);
if(flag)
break;
}
}
if(flag) cout<<i+1;
else cout<<'0';
return 0;
}