Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3. import math
  4. import os
  5. import random
  6. import re
  7. import sys
  8.  
  9. # Complete the repeatedString function below.
  10. def repeatedString(s, n):
  11. count = 0
  12. for i in s:
  13. if i == 'a':
  14. count = count + 1
  15.  
  16. length = len(s);
  17. num_repeat = math.floor(n/length);
  18.  
  19. total_count_a = num_repeat * count;
  20.  
  21. #handle remainder
  22. remaining_letters = n - (num_repeat * length)
  23.  
  24. for i in range(0, remaining_letters):
  25. if s[i] == 'a':
  26. total_count_a += 1
  27.  
  28. return total_count_a
  29.  
  30.  
  31.  
  32. if __name__ == '__main__':
  33. fptr = open(os.environ['OUTPUT_PATH'], 'w')
  34.  
  35. s = input()
  36.  
  37. n = int(input())
  38.  
  39. result = repeatedString(s, n)
  40.  
  41. fptr.write(str(result) + '\n')
  42.  
  43. fptr.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement