-
Notifications
You must be signed in to change notification settings - Fork 5
/
P10_NAME2.py
53 lines (52 loc) · 1.34 KB
/
P10_NAME2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# A man with name M is allowed to marry a woman with name W, only if M is a subsequence of W or W is a
# subsequence of M.
#
# A is said to be a subsequence of B, if A can be obtained by deleting some elements of B without changing
# the order of the remaining elements.
#
# Your task is to determine whether a couple is allowed to marry or not, according to Archer's rule.
#
# Input
# The first line contains an integer T, the number of test cases. T test cases follow. Each test case
# contains two space separated strings M and W.
#
# Output
# For each test case print "YES" if they are allowed to marry, else print "NO". (quotes are meant for
# clarity, please don't print them)
#
# Constraints
# 1 ≤ T ≤ 100
# 1 ≤ |M|, |W| ≤ 25000 (|A| denotes the length of the string A.)
# All names consist of lowercase English letters only.
#
# Example
# Input:
# 3
# john johanna
# ira ira
# kayla jayla
#
# Output:
# YES
# YES
# NO
testCases = int(input())
while testCases:
testCases -= 1
M, W = map(str, input().split())
countM = 1
countW = 1
for i in M:
result = W.find(i)
if result == -1:
countM = 0
break
for i in W:
result = M.find(i)
if result == -1:
countW = 0
break
if (countM == 1) or (countW == 1):
print('YES')
else:
print('NO')