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 65d7a87

Browse files
Add files via upload
1 parent 335cff3 commit 65d7a87

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

‎Merge the Tools!.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Consider the following:
2+
3+
# A string, , of length where .
4+
# An integer, , where is a factor of .
5+
# We can split into subsegments where each subsegment, , consists of a contiguous block of characters in . Then, use each to create string such that:
6+
7+
# The characters in are a subsequence of the characters in .
8+
# Any repeat occurrence of a character is removed from the string such that each character in occurs exactly once. In other words, if the character at some index in occurs at a previous index in , then do not include the character in string .
9+
# Given and , print lines where each line denotes string .
10+
11+
# Input Format
12+
13+
# The first line contains a single string denoting .
14+
# The second line contains an integer, , denoting the length of each subsegment.
15+
16+
# Constraints
17+
18+
# , where is the length of
19+
# It is guaranteed that is a multiple of .
20+
# Output Format
21+
22+
# Print lines where each line contains string .
23+
24+
# Sample Input
25+
26+
# AABCAAADA
27+
# 3
28+
# Sample Output
29+
30+
# AB
31+
# CA
32+
# AD
33+
# Explanation
34+
35+
# String is split into equal parts of length . We convert each to by removing any subsequent occurrences non-distinct characters in :
36+
37+
# We then print each on a new line.
38+
39+
40+
41+
def merge_the_tools(string, k):
42+
list1 = []
43+
n = len(string)
44+
parts = n//k
45+
for i in range(0, len(string), k):
46+
s = ""
47+
for j in string[i : i + k]:
48+
if j in s:
49+
continue
50+
else:
51+
s += j
52+
print(s)
53+
if __name__ == '__main__':
54+
string, k = input(), int(input())
55+
merge_the_tools(string, k)

0 commit comments

Comments
(0)

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