This repo will not have much explanation but will be use to store any tricks and solutions for any programing questions whether local or international events.
I want to improve on different programming languages, so this repo would have different solutions consists of:
- Python
- C++
- Node JS
- Rust (Hopefully)
# Input
arr = [int(x) for x in input().split()]
x,y = map(int,input().split())
x = int(input())
M = list(map(int,input().split()))
# One Liner
print("boleh") if (x % 2 == 0) and (x > 5) else print("tidak boleh")
for i in range(10): print(i)
for i in range(int(input())): print(sum([int(digits) for digits in input()]))
# Sort List & Sum (Top 5)
sum(sorted(M)[-5:])
# Floor Div
x = 6 // 4
# BinaryToDecimal
def binaryToDecimal(n):
return int(n,2)
print(binaryToDecimal("111"))
# Sum
print(sum([int(digits) for digits in input()]))
# Format
print("%.2f" % (Y-X-0.5)) # 10.00
print("{0:.2f}".format(Y)) # 1.50
print("%.2f AND %.2f" % (X,Y)) # 0.50 AND 0.20
# Multiple of all values in a list
from functools import reduce
A = [1, 2, 3]
print(reduce((lambda x, y: x * y), A))
# Check Whole Number
if i % 1 == 0:
print(int(i)) # 1.5
else:
print(i) # 1
# Groupby
# Examples => "AAAAABBBBCCCCCDDDDAAAABBBB"
import itertools
for letter, _ in itertools.groupby(inputs):
print(letter)
# Count Number of Factors
#====Example(1)=====
from functools import reduce
def printDivisors(n) :
i = 1
sum = 0
while i <= n :
if (n % i==0) :
sum += 1
i = i + 1
return sum
print(printDivisors(100))
#====Example(2)====
import math
def printDivisors(n) :
list = []
count = 0
# List to store half of the divisors
for i in range(1, int(math.sqrt(n) + 1)) :
if (n % i == 0) :
# Check if divisors are equal
if (n / i == i) :
count += 1
else :
# Otherwise print both
count += 1
list.append(int(n / i))
# The list will be printed in reverse
for i in list[::-1] :
count += 1
return count
print(printDivisors(100))
#====Example(3)====
from functools import reduce
def printDivisors(n):
return len(set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
print(printDivisors(100))
# Input (Define1)
// Define Input
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.replace(/\s*$/, '')
.split('\n')
.map(str => str.replace(/\s*$/, ''));
main();
});
function readLine() {
return inputString[currentLine++];
}
# Input (Define2)
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";
process.stdin.on("data", function (input) {
stdin_input += input;
});
process.stdin.on("end", function () {
main(stdin_input);
});
# Input Usage
const n = parseInt(readLine());
# Assign (Split)
var arr = input.split("\n");
var [x1,y1] = Object.values(arr)[0].split(" ").map(Number);
var [x2,y2] = Object.values(arr)[1].split(" ").map(Number);
# Convert
B.toString()
# One Liner
((x % 2 == 0) && (x > 5)) ? process.stdout.write("boleh") : process.stdout.write("tidak boleh");
#==Python==
- https://gist.github.com/jenthone/300e6fbbd9d5ba39fe6cd4fa107b4477
#==Algorithm==
- https://www.techiedelight.com/