Skip to content

Commit

Permalink
Update to 12
Browse files Browse the repository at this point in the history
  • Loading branch information
chance2021 committed May 1, 2024
1 parent b1b5c35 commit 79f48cd
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 0 deletions.
28 changes: 28 additions & 0 deletions python/practice-together/006-staircase/staircase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Staircase
# https://www.hackerrank.com/challenges/staircase/problem?isFullScreen=true

#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'staircase' function below.
#
# The function accepts INTEGER n as parameter.
#

def staircase(n):
space = ' '
hashtag = '#'

for i in range(1,n+1):
print(f'{space * (n-i)}{hashtag * i}')

if __name__ == '__main__':
n = int(input().strip())

staircase(n)
24 changes: 24 additions & 0 deletions python/practice-together/007-miniMaxSum/miniMaxSum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'miniMaxSum' function below.
#
# The function accepts INTEGER_ARRAY arr as parameter.
#

def miniMaxSum(arr):
min_sum = sum(arr) - max(arr)
max_sum = sum(arr) - min(arr)
print(f'{min_sum} {max_sum}')

if __name__ == '__main__':

arr = list(map(int, input().rstrip().split()))

miniMaxSum(arr)
29 changes: 29 additions & 0 deletions python/practice-together/007-miniMaxSum/miniMaxSum2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'miniMaxSum' function below.
#
# The function accepts INTEGER_ARRAY arr as parameter.
#

def miniMaxSum(arr):
sum = min = max = arr[0]
for n in arr[1:]:
if n < min:
min = n
elif n > max:
max = n
sum += n
print(f"{sum-max} {sum-min}")

if __name__ == '__main__':

arr = list(map(int, input().rstrip().split()))

miniMaxSum(arr)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'birthdayCakeCandles' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY candles as parameter.
#

def birthdayCakeCandles(candles):
candles.sort()
tallest = candles[-1]
return candles.count(tallest)

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

candles_count = int(input().strip())

candles = list(map(int, input().rstrip().split()))

result = birthdayCakeCandles(candles)

fptr.write(str(result) + '\n')

fptr.close()
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'birthdayCakeCandles' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY candles as parameter.
#

def birthdayCakeCandles(candles):
count = 1
tallest = candles[0]
for i in candles[1:]:
if i == tallest:
count += 1
elif i > tallest:
tallest = i
count = 1
return count

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

candles_count = int(input().strip())

candles = list(map(int, input().rstrip().split()))

result = birthdayCakeCandles(candles)

fptr.write(str(result) + '\n')

fptr.close()
42 changes: 42 additions & 0 deletions python/practice-together/009-timeConversion/timeConversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'gradingStudents' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts INTEGER_ARRAY grades as parameter.
#

def gradingStudents(grades):
grades_after_round = []
for i in grades:
if i < 38:
grades_after_round.append(i)
elif 5 - i % 5 < 3:
grades_after_round.append(i + 5 - i % 5)
else:
grades_after_round.append(i)
return grades_after_round
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

grades_count = int(input().strip())

grades = []

for _ in range(grades_count):
grades_item = int(input().strip())
grades.append(grades_item)

result = gradingStudents(grades)

fptr.write('\n'.join(map(str, result)))
fptr.write('\n')

fptr.close()
40 changes: 40 additions & 0 deletions python/practice-together/010- gradingStudents/gradingStudents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'timeConversion' function below.
#
# The function is expected to return a STRING.
# The function accepts STRING s as parameter.
#

def timeConversion(s):
AM_or_PM = s[-2:]
hour = s[:2]
if AM_or_PM == "AM":
if hour == "12":
s = "00" + s[2:-2]
else:
s = s[:-2]
elif AM_or_PM == "PM":
if hour == "12":
s = "12" + s[2:-2]
else:
s = str(int(hour) + 12) + s[2:-2]
return s

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

s = input()

result = timeConversion(s)

fptr.write(result + '\n')

fptr.close()
48 changes: 48 additions & 0 deletions python/practice-together/011-kangaroo/kangaroo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'kangaroo' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. INTEGER x1
# 2. INTEGER v1
# 3. INTEGER x2
# 4. INTEGER v2
#

def kangaroo(x1, v1, x2, v2):
if x1 < x2 and v1 <= v2:
return 'NO'
elif x1 > x2 and v1 >= v2:
return 'NO'
elif (x1 - x2) % (v2 - v1) != 0:
return 'NO'
else:
return 'YES'


if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

first_multiple_input = input().rstrip().split()

x1 = int(first_multiple_input[0])

v1 = int(first_multiple_input[1])

x2 = int(first_multiple_input[2])

v2 = int(first_multiple_input[3])

result = kangaroo(x1, v1, x2, v2)

fptr.write(result + '\n')

fptr.close()
43 changes: 43 additions & 0 deletions python/practice-together/012-breakingRecords/breakingRecords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'breakingRecords' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts INTEGER_ARRAY scores as parameter.
#

def breakingRecords(scores):
highest_record = scores[0]
lowest_record = scores[0]
count_break_highest = 0
count_break_lowest = 0
for i in range(1, len(scores)):
if scores[i] > highest_record:
highest_record = scores[i]
count_break_highest += 1
elif scores[i] < lowest_record:
lowest_record = scores[i]
count_break_lowest += 1
return count_break_highest, count_break_lowest


if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input().strip())

scores = list(map(int, input().rstrip().split()))

result = breakingRecords(scores)

fptr.write(' '.join(map(str, result)))
fptr.write('\n')

fptr.close()

0 comments on commit 79f48cd

Please sign in to comment.