Skip to content

Commit 7e6c276

Browse files
committed
updated string sub domain solutions - partial
1 parent cb0d3bd commit 7e6c276

File tree

10 files changed

+154
-97
lines changed

10 files changed

+154
-97
lines changed

Introduction/ReadingRawInput.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'''
2+
Title : Reading Raw Input
3+
Subdomain : Introduction
4+
Domain : Python
5+
Author : Ahmedur Rahman Shovon
6+
Created : 15 July 2016
7+
'''
8+
# Enter your code here. Read input from STDIN. Print output to STDOUT
9+
name=raw_input()
10+
print name

Strings/DesignerDoorMat.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
'''
1+
"""
22
Title : Designer Door Mat
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/designer-door-mat/problem
8-
'''
9-
N, M = map(int,input().split()) # More than 6 lines of code will result in 0 score. Blank lines are not counted.
10-
for i in range(1,N,2):
11-
print(int((M-3*i)/2)*'-'+(i*'.|.')+int((M-3*i)/2)*'-')
12-
print(int((M-7)/2)*'-'+'WELCOME'+int((M-7)/2)*'-')
13-
for i in range(N-2,-1,-2):
14-
print(int((M-3*i)/2)*'-'+(i*'.|.')+int((M-3*i)/2)*'-')
8+
"""
9+
N, M = map(int, input().split())
10+
for i in range(1, N, 2):
11+
print(int((M - 3 * i) / 2) * '-' + (i * '.|.') + int((M - 3 * i) / 2) * '-')
12+
print(int((M - 7) / 2) * '-' + 'WELCOME' + int((M - 7) / 2) * '-')
13+
for i in range(N - 2, -1, -2):
14+
print(int((M - 3 * i) / 2) * '-' + (i * '.|.') + int((M - 3 * i) / 2) * '-')

Strings/Findastring.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
'''
1+
"""
22
Title : Find a string
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/find-a-string/problem
8-
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
s=raw_input()
11-
ss=raw_input()
12-
cnt=0
13-
len_s=len(s)
14-
len_ss=len(ss)
15-
for i in range(0,len_s):
16-
tmp=s[i:i+len_ss]
17-
if(tmp==ss):
18-
cnt=cnt+1
19-
print cnt
8+
"""
9+
10+
11+
def count_substring(string, sub_string):
12+
count_sub_string = 0
13+
for i in range(len(string) - len(sub_string) + 1):
14+
if string[i:i + len(sub_string)] == sub_string:
15+
count_sub_string += 1
16+
return count_sub_string
17+
18+
19+
if __name__ == '__main__':
20+
string = input().strip()
21+
sub_string = input().strip()
22+
23+
count = count_substring(string, sub_string)
24+
print(count)

Strings/Mutations.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
'''
1+
"""
22
Title : Mutations
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7-
Updated : 25 October 2019
7+
Updated : 08 July 2020
88
Problem : https://www.hackerrank.com/challenges/python-mutations/problem
9-
'''
9+
"""
10+
11+
1012
def mutate_string(string, position, character):
11-
return string[:position]+character+string[position+1:]
13+
chars = list(string)
14+
chars[position] = character
15+
return "".join(chars)
16+
1217

18+
if __name__ == '__main__':
19+
s = input()
20+
i, c = input().split()
21+
s_new = mutate_string(s, int(i), c)
22+
print(s_new)

Strings/StringSplitandJoin.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
'''
1+
"""
22
Title : String Split and Join
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 08 July 2020
77
Problem : https://www.hackerrank.com/challenges/python-string-split-and-join/problem
8-
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
print "-".join(raw_input().strip().split())
8+
"""
9+
10+
11+
def split_and_join(sentence):
12+
return "-".join(sentence.split())
13+
14+
15+
if __name__ == '__main__':
16+
line = input()
17+
result = split_and_join(line)
18+
print(result)

Strings/StringValidators.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
'''
1+
"""
22
Title : String Validators
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 08 July 2020
78
Problem : https://www.hackerrank.com/challenges/string-validators/problem
8-
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
inputStr=input()
11-
resalnum = False
12-
resalpha = False
13-
resdigit = False
14-
reslower = False
15-
resupper = False
16-
for i in inputStr:
17-
if(i.isalnum()):
18-
resalnum=True
19-
if(i.isalpha()):
20-
resalpha=True
21-
if(i.isdigit()):
22-
resdigit=True
23-
if(i.islower()):
24-
reslower=True
25-
if(i.isupper()):
26-
resupper=True
27-
28-
print(resalnum)
29-
print(resalpha)
30-
print(resdigit)
31-
print(reslower)
32-
print(resupper)
9+
"""
10+
if __name__ == '__main__':
11+
s = input()
12+
flag_alnum = False
13+
flag_alpha = False
14+
flag_digit = False
15+
flag_lower = False
16+
flag_upper = False
17+
for i in s:
18+
if i.isalnum():
19+
flag_alnum = True
20+
if i.isalpha():
21+
flag_alpha = True
22+
if i.isdigit():
23+
flag_digit = True
24+
if i.islower():
25+
flag_lower = True
26+
if i.isupper():
27+
flag_upper = True
28+
29+
print(flag_alnum)
30+
print(flag_alpha)
31+
print(flag_digit)
32+
print(flag_lower)
33+
print(flag_upper)

Strings/TextAlignment.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
'''
1+
"""
22
Title : Text Alignment
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 08 July 2020
78
Problem : https://www.hackerrank.com/challenges/text-alignment/problem
8-
'''
9-
#Replace all ______ with rjust, ljust or center.
9+
"""
1010

11-
thickness = int(input()) #This must be an odd number
11+
thickness = int(input())
1212
c = 'H'
1313

14-
#Top Cone
14+
# Top Cone
1515
for i in range(thickness):
16-
print((c*i).rjust(thickness-1)+c+(c*i).ljust(thickness-1))
16+
print((c * i).rjust(thickness - 1) + c + (c * i).ljust(thickness - 1))
1717

18-
#Top Pillars
19-
for i in range(thickness+1):
20-
print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6))
18+
# Top Pillars
19+
for i in range(thickness + 1):
20+
print((c * thickness).center(thickness * 2) + (c * thickness).center(thickness * 6))
2121

22-
#Middle Belt
23-
for i in range((thickness+1)//2):
24-
print((c*thickness*5).center(thickness*6))
22+
# Middle Belt
23+
for i in range((thickness + 1) // 2):
24+
print((c * thickness * 5).center(thickness * 6))
2525

26-
#Bottom Pillars
27-
for i in range(thickness+1):
28-
print((c*thickness).center(thickness*2)+(c*thickness).center(thickness*6))
26+
# Bottom Pillars
27+
for i in range(thickness + 1):
28+
print((c * thickness).center(thickness * 2) + (c * thickness).center(thickness * 6))
2929

30-
#Bottom Cone
30+
# Bottom Cone
3131
for i in range(thickness):
32-
print(((c*(thickness-i-1)).rjust(thickness)+c+(c*(thickness-i-1)).ljust(thickness)).rjust(thickness*6))
32+
print(((c * (thickness - i - 1)).rjust(thickness) + c + (c * (thickness - i - 1)).ljust(thickness)).rjust(
33+
thickness * 6))

Strings/TextWrap.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
'''
1+
"""
22
Title : Text Wrap
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 08 July 2020
78
Problem : https://www.hackerrank.com/challenges/text-wrap/problem
8-
'''
9+
"""
910
import textwrap
10-
s = input()
11-
w = int(input().strip())
12-
print(textwrap.fill(s,w))
11+
12+
13+
def wrap(string, max_width):
14+
return textwrap.fill(string, max_width)
15+
16+
17+
if __name__ == '__main__':
18+
string, max_width = input(), int(input())
19+
result = wrap(string, max_width)
20+
print(result)

Strings/WhatsYourName.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
'''
1+
"""
22
Title : Whats Your Name?
33
Subdomain : Introduction
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/whats-your-name/problem
8-
'''
9-
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
fname=raw_input()
11-
lname=raw_input()
12-
print "Hello "+fname+" "+lname+"! You just delved into python."
8+
"""
9+
10+
11+
def print_full_name(a, b):
12+
print("Hello {} {}! You just delved into python.".format(a, b))
13+
14+
15+
if __name__ == '__main__':
16+
first_name = input()
17+
last_name = input()
18+
print_full_name(first_name, last_name)

Strings/sWAPcASE.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
'''
1+
"""
22
Title : sWAP cASE
33
Subdomain : Strings
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
6-
Created : 15 July 2016
6+
Created : 16 July 2016
7+
Updated : 08 July 2020
78
Problem : https://www.hackerrank.com/challenges/swap-case/problem
8-
'''
9-
__author__ = 'arsho'
10-
def swap_case(s):
11-
newstring = ""
12-
13-
for item in s:
14-
if item.isupper():
15-
newstring += item.lower()
9+
"""
10+
11+
12+
def swap_case(sentence):
13+
updated_s = ""
14+
for c in sentence:
15+
if c.isupper():
16+
updated_s += c.lower()
17+
elif c.islower():
18+
updated_s += c.upper()
1619
else:
17-
newstring += item.upper()
18-
19-
return newstring
20+
updated_s += c
21+
return updated_s
22+
23+
24+
if __name__ == '__main__':
25+
s = input()
26+
result = swap_case(s)
27+
print(result)

0 commit comments

Comments
 (0)