-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabbreviation_1.py
More file actions
42 lines (32 loc) · 830 Bytes
/
abbreviation_1.py
File metadata and controls
42 lines (32 loc) · 830 Bytes
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
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the abbreviation function below.
def abbreviation(a, b):
if len(b) > len(a):
return 'NO'
if len(b) == len(a):
a = a.upper()
return 'YES' if a == b else 'NO'
ap = bp = 0
while ap < len(a):
if bp < len(b) and (a[ap] == b[bp] or a[ap].upper() == b[bp]):
ap += 1
bp += 1
elif a[ap].islower():
ap += 1
else:
break
return 'YES' if bp == len(b)-1 and ap == len(a) else 'NO'
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input())
for q_itr in range(q):
a = input()
b = input()
result = abbreviation(a, b)
fptr.write(result + '\n')
fptr.close()