Last active
November 24, 2017 20:50
-
-
Save JaDogg/c349b523ae91f622a0e56cd1d3594ee1 to your computer and use it in GitHub Desktop.
Python3 HackerRank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# input single integer | |
n = int(input().strip()) | |
# 2 Integers in 2 lines | |
n, m = int(input().strip()), int(input().strip()) | |
# 2 Integers in 1 line | |
n, m = input().strip().split(' ') | |
n, m = int(n), int(m) | |
# Array of integers seperated by space | |
a = list(map(int, input().strip().split(' '))) | |
# Array of integers seperated by space sorted | |
a = sorted(list(map(int, input().strip().split(' ')))) | |
# print matrix | |
def printm(mat): | |
for row in mat: | |
print(' '.join(map(str, row))) | |
# print array | |
def printa(arr): | |
print(' '.join(map(str, arr))) | |
# Convert a number to a list of integers (base 10) | |
# Replace 10 with the any other base to get it working with any other base | |
def num2lst(num): | |
arr = [] | |
if num == 0: | |
return [0] | |
c = num | |
while c > 0: | |
c, r = divmod(c, 10) | |
arr.insert(0, r) | |
return arr | |
# Convert a list of integer to a number (base 10) | |
# Replace 10 with the any other base to get it working with any other base | |
def lst2num(lst): | |
num = 0 | |
mul = 1 | |
for n in reversed(lst): | |
num += n * mul | |
mul *= 10 | |
return num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment