Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7242bb6

Browse files
Create Append_and_Delete.py
1 parent 55ef71c commit 7242bb6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎Implimentation/Append_and_Delete.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the appendAndDelete function below.
10+
def appendAndDelete(s, t, k):
11+
min_len = min(len(s), len(t))
12+
first_different_index = min_len
13+
14+
for i in range(min_len):
15+
if s[i] != t[i]:
16+
first_different_index = i
17+
break
18+
19+
necessary_operations = len(s) + len(t) - 2 * first_different_index
20+
21+
return("Yes" if k == necessary_operations or (k >= necessary_operations and (k - necessary_operations) % 2 == 0 ) or k >= len(s) + len(t) else "No")
22+
23+
if __name__ == '__main__':
24+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
25+
26+
s = input()
27+
28+
t = input()
29+
30+
k = int(input())
31+
32+
result = appendAndDelete(s, t, k)
33+
34+
fptr.write(result + '\n')
35+
36+
fptr.close()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /