病毒感染监测问题

描述

医学研究者最近发现了某些新病毒,通过对这些病毒的分析,得知它们的DNA序列都是环状的。现在研究者收集了大量的病毒DNA和人的DNA数据,想快速检测出这些人是否感染了相应的病毒。为方便研究,研究者将人的DNA和病毒的DNA均表示成由一些小写字母组成的字符串,然后检测某种病毒的DNA序列是否在患者的DNA序列中出现过,如果出现过,则此人感染了病毒,否则没有感染。注意:人的DNA序列是线性的,而病毒的DNA序列是环状的。

输入

多组数据,每组数据有一行,为序列A和B,A对应病毒的DNA序列,B对应人的DNA序列。A和B都为“0”时输入结束。

输出

对于每组数据输出一行,若患者感染了病毒输出“YES”,否则输出“NO”。

输入样例 1

abbab abbabaab
baa cacdvcabacsd
abc def   
0 0

输出样例 1

YES
YES
NO

#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int Index_BF(const string &str1, const string &str2, int pos){
  int i = pos;
  int j = 0;
  int len1 = str1.size();
  int len2 = str2.size();
  while (i<len1&&j<len2){
     if (str1[i] == str2[j]){
             i++;
             j++;
         }
     else{
             i = i - j + 1;
             j = 0;
         }
     }
     if (j >= len2)
         return i - len2;
     else
         return -1;
 }
 
 int main()
 {
     int pos = 0;
     string str1;
     string str2;
     int result;
    while (cin >> str2 >> str1)
    {
        if (str1 == "0"&&str2 == "0")break;
        int m=str2.length();
		string str3 = str2 + str2;	
      	for(int i=0;i<m;i++)
      	{
         	string temp=str3.substr(i,m);	
         	result =Index_BF(str1,temp,pos);	
        	if(result!=-1) break;			
      	}
     	if(result!=-1)
         cout<<"YES"<<endl;
      	else
         cout<<"NO"<<endl;      
    }
    return 0;
 }

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yvonnae

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值