-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppend and Delete
More file actions
55 lines (44 loc) · 1.07 KB
/
Append and Delete
File metadata and controls
55 lines (44 loc) · 1.07 KB
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
54
55
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the appendAndDelete function below.
def appendAndDelete(s, t, k):
flag=0
while(k):
if len(s)==0:
k=k-len(t)
if k>=0:
flag=1
break
else:
break
elif s in t:
if s[0]==t[0]:
if len(t)-len(s)==k:
flag=1
break
elif len(t)-len(s)<k:
if len(s)%2==len(t)%2: #if both are even or odd
if k%2==0:
flag=1
else:
if k%2!=0:
flag=1
else:
break
s=s[:-1]
k-=1
if flag==0:
return 'No'
return 'Yes'
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
t = input()
k = int(input())
result = appendAndDelete(s, t, k)
fptr.write(result + '\n')
fptr.close()