当前位置:网站首页>Hermit crab and anemone

Hermit crab and anemone

2022-07-19 06:54:00 winkiii

describe

Hermit crab and anemone are a pair of cooperative symbiotic partners . Anemone is the most competent guard of hermit crab . It uses poisonous tentacles to sting all animals that dare to come close to them , Protect hermit crabs . And the hermit crab carries the sea anemone with difficulty in action , Go out looking for food , share each other's fortunes . But not all hermit crabs and anemones can be partners . It depends on whether the anemone's body conforms to the shell of the hermit crab . The anemone's body is wrinkled , The shell of the hermit crab is also uneven , We can use a string of uppercase letters to indicate their high and low levels , among A representative 0,B representative 1, By analogy . We call the sum of the two equal 25 Even if it is consistent , such as A and Z consistent ,B And Y Coincide , By analogy . As long as the sequence of the body part of the anemone is consistent with the sequence of the shell of the hermit crab , Say they can live together . such as : 1. The folds of anemones are "ABCDEFG", Hermit crab yes "ZYXWVUT". such , They can completely match . 2. The folds of anemones are "AHBICJDKELFMGN", Hermit crab yes "ZYXWVUT". such , Hermit crabs can be part of the sequence with sea anemones "ABCDEFG" consistent ( Be careful : Some sequences do not change the original sequence of characters , such as "ACB" It's not part of its sequence ). 3. The folds of anemones are "ABCD", Hermit crab yes "ZYXWVUT". such , Although the anemone can completely match the front section of the hermit crab , But it is smaller than the hermit crab , Can not completely protect the safety of hermit crabs , All of them are unsuitable . 4. The folds of anemones are "HIJKLMNOPQ", Hermit crab yes "ZYXWVUT". such , They can be completely mismatched . Here are two strings for you S1、S2, Respectively represents the shell of anemone and hermit crab , For them to live happily in the future , Please help calculate whether they match .

Input
The input includes multiple sets of test data . Each set of test data includes two strings H、J, Respectively represents the shell of anemone and the shell of hermit crab . It can ensure that their length is less than 100000. Enter to 0 0 end .

Output
If the shells of hermit crab and anemone can match , It outputs "Yes", Otherwise output "No".

sample input 1

ABCDEFG ZYXWVUT
AHBICJDKELFMGN ZYXWVUT
ABCD ZYXWVUT
HIJKLMNOPQ ZYXWVUT
0 0

sample output 1

Yes
Yes
No
No

#include<string.h>
#include<stdio.h>

char h[100010],j[100010];
int main(){
    
    while(scanf("%s %s",h,j)){
    
        if(strcmp(h,"0")==0 && strcmp(j,"0")==0) break;
        int i,k=0;
        for(i=0;i<strlen(h);++i){
    
        if(h[i]-'A'+j[k]-'A'==25)
            k++;
        }
        if(k>=strlen(j))
            printf("Yes\n");
        else
            printf("No\n");
    }
}
原网站

版权声明
本文为[winkiii]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207170519575582.html