病毒感染检测
题目:
代码:
#include <iostream>
#include <string>
using namespace std;
bool bf(string s,string t){
int i=0,j=0;
while(i<s.length() && j<t.length()){
if(s[i]==t[j]){
i++;j++;
}else{
i=i-j+1;
j=0;
}
}
if(j==t.length()){
return true;
}
return false;
}
bool index(string s,string t){
string str;
int m=t.length()/2;
bool res;
for(int k=0;k<m;k++){
str=t.substr(k,m);
res=bf(s,str);
if(res){
return true;
}
}
return false;
}
int main(){
string str1,str2; //str1人的DNA,str2病毒DNA
cout<<"请输入病人DNA:";
cin>>str1;
cout<<"请输入病毒DNA:";
cin>>str2;
str2+=str2;
bool res;
res=index(str1,str2);
if(res){
cout<<"true";
}else{
cout<<"false";
}
return 0;
}