diff --git a/ps008.py b/ps008.py new file mode 100644 index 0000000..1f28fac --- /dev/null +++ b/ps008.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Oct 5 00:05:26 2019 + +@author: tanma +""" + +import sys + +def get_prod(x, k): + n = list(str(x)) + l = [int(i) for i in n] + prods = [] + for i in range(len(l)-k): + a = 1 + for j in range(i,i+k): + a *= l[j] + prods.append(a) + + return max(prods) + + +t = int(input().strip()) +for a0 in range(t): + n,k = input().strip().split(' ') + n,k = [int(n),int(k)] + num = input().strip() + print(get_prod(num, k)) \ No newline at end of file diff --git a/ps017.py b/ps017.py new file mode 100644 index 0000000..1e9bcac --- /dev/null +++ b/ps017.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Oct 5 12:20:28 2019 + +@author: tanma +""" + +numbersDict = { +0:"Zero", +1:"One", +2:"Two", +3:"Three", +4:"Four", +5:"Five", +6:"Six", +7:"Seven", +8:"Eight", +9:"Nine", +10:"Ten", +11:"Eleven", +12:"Twelve", +13:"Thirteen", +14:"Fourteen", +15:"Fifteen", +16:"Sixteen", +17:"Seventeen", +18:"Eighteen", +19:"Nineteen", +20:"Twenty", +30:"Thirty", +40:"Forty", +50:"Fifty", +60:"Sixty", +70:"Seventy", +80:"Eighty", +90:"Ninety" +} + +def numberLetters(num): + + letters = "" + + if 0 < num <= 20: + letters += numbersDict[num] + + if 21 <= num <= 99: + a,b = divmod(num, 10) + if b == 0: + letters += numbersDict[a*10] + else: + letters += numbersDict[a*10] + " " + numbersDict[b] + + if 100 <= num <= 999: + if num % 100 == 0: + letters += numbersDict[int(num / 100)] + "Hundred" + else: + digit = int(num / 100) + num = num - digit * 100 + if 0 < num <= 20: + letters += numbersDict[digit] + "Hundred " + numbersDict[num] + if 21 <= num <= 99: + a,b = divmod(num, 10) + if b == 0: + letters += numbersDict[digit] + "Hundred " + numbersDict[a*10] + else: + letters += numbersDict[digit] + "Hundred " + numbersDict[a*10] + numbersDict[b] + if num == 1000: + letters += "One Thousand" + + return letters + +t = int(input().strip()) +for a0 in range(t): + print(numberLetters(int(input()))) + diff --git a/ps018.py b/ps018.py new file mode 100644 index 0000000..12a9db0 --- /dev/null +++ b/ps018.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Oct 5 11:42:15 2019 + +@author: tanma +""" + +def recSumAtRow(rowData, rowNum): + for i in range(len(rowData[rowNum])): + rowData[rowNum][i] += max([rowData[rowNum+1][i],rowData[rowNum+1][i+1]]) + if len(rowData[rowNum])==1: + return rowData[rowNum][0] + else: + return recSumAtRow(rowData, rowNum-1) + + +t = int(input().strip()) +for a0 in range(t): + n = input().strip() + n = int(n) + row = [] + for i in range(n): + a = [int(i) for i in input().split(" ")] + row.append(a) + print(recSumAtRow(row, len(row)-2)) \ No newline at end of file diff --git a/ps019.py b/ps019.py new file mode 100644 index 0000000..0c51d04 --- /dev/null +++ b/ps019.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Oct 5 12:07:03 2019 + +@author: tanma +""" + +import time,calendar + +calendar.setfirstweekday(6) + +def sundays(year): + counter = 0 + for month in range(1,13): + cal = calendar.monthcalendar(year,month) + if cal[0][0]: + counter += 1 + return counter + +t = int(input().strip()) +for a0 in range(t): + n = [int(i) for i in input().split(" ")] + ne = [int(i) for i in input().split(" ")] + total = 0 + for i in range(n[0],ne[0]): + total += sundays(i) + print(total) \ No newline at end of file