-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepeated_String.py
More file actions
42 lines (29 loc) · 830 Bytes
/
Repeated_String.py
File metadata and controls
42 lines (29 loc) · 830 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
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the repeatedString function below.
def repeatedString(s, n):
arr = []
aInString = 0
leftOverCount = 0
timesRan = (int)(n/len(s))
leftOver = n%len(s)
arr=s[0:leftOver]
#for every char in the s check count the a's
for i in range(len(s)):
if s[i] == 'a':
aInString +=1
#adds leftover count while checking for how many a's in reg count
if i < len(arr) and s[i] =='a':
leftOverCount +=1
return timesRan*aInString + leftOverCount
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
n = int(input())
result = repeatedString(s, n)
fptr.write(str(result) + '\n')
fptr.close()