A program that verifies that a specific string can be created from a Python string

Asked 2 years ago, Updated 2 years ago, 16 views

For example,

First of all, you get two strings

Alice in wonderland

Aciwl

This is how you get the input The string Aciwl is a string that can be created by just a few guys from Alice in Wonderland, so the output value is "possible."

If not possible

Alice in wonderland

Awalc

This is the case Unless you shuffle the order, no matter how many times you erase others, you can't create the string below.

I don't know what function to use in this case, so I'm asking this question <

python

2022-09-20 20:05

2 Answers

def compare(a,b):
    ap = 0
    bp = 0

    if a[ap] != b[bp]:
        print("Not matched")

    ap += 1
    bp += 1

    while ap < len(a) and bp < len(b):
        if a[ap] != b[bp]:
            ap += 1
        else:
            ap += 1
            bp += 1

    if bp != len(b):
        print("Not Match")
    else:
        print("Match :D")

a = 'Alice in wonderland'
b = 'Aciwl'

compare(a,b)

It's a matter of creating a function, and from now on, whoever it is, whoever it is...

I think it's polite to show a minimum attempt when asked.


2022-09-20 20:05

s = input()
t = input()


for i in range(len(t)-1):
    Find = True
        if s.find(t[i])!= -1:
       s = s[s.find(t[i])+1:]
    else:
        Find = False
if Find:
    print("Yes")
else:
    print("No")

It was blocked while making it like this.

I guess I didn't even think about attaching it because I was embarrassed to post my skills since it started the day before yesterday. Thank you very much for your help


2022-09-20 20:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.