-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppendAndDelete.py
More file actions
51 lines (41 loc) · 1018 Bytes
/
Copy pathAppendAndDelete.py
File metadata and controls
51 lines (41 loc) · 1018 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
43
44
45
46
47
48
49
50
51
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'appendAndDelete' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. STRING s
# 2. STRING t
# 3. INTEGER k
#
def appendAndDelete(s, t, k):
if k >= len(s) + len(t):
return 'Yes'
counter = 0
for i in range(min(len(s), len(t))):
if s[i] == t[i]:
counter += 1
else:
break
print(counter, len(s) + len(t))
if counter == 0 and len(s) + len(t) <= k:
return 'Yes'
elif len(s) + len(t) - counter*2 == k:
return 'Yes'
elif (counter == len(s) or counter == len(t)) and (k-abs(len(s)-len(t)))%2 == 0:
return 'Yes'
else:
return 'No'
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
t = input()
k = int(input().strip())
result = appendAndDelete(s, t, k)
fptr.write(result + '\n')
fptr.close()