def write_1d(a): length = len(a) stdio.writeln(length) for i in range(length): element = a[i] if isinstance(element, bool): if element == True: stdio.write(1) else: stdio.write(0) else: stdio.write(element) stdio.write(' ') stdio.writeln()
def write_2d(a): row_count = len(a) col_count = len(a[0]) stdio.writeln(str(row_count) + ' ' + str(col_count)) for row in range(row_count): for col in range(col_count): element = a[row][col] if isinstance(element, bool): if element == True: stdio.write(1) else: stdio.write(0) else: stdio.write(element) stdio.write(' ') stdio.writeln()
import sys from introcs.stdlib import stdio n = int(sys.argv[1]) for i in range(1, n + 1): for j in range(1, n + 1): if (i % j == 0) or (j % i == 0): stdio.write('* ') else: stdio.write(' ') stdio.writeln()
from introcs.stdlib import stdio for i in range(1000, 2000): stdio.write(f"{i} ") if (i % 5) == 0: stdio.writeln()
import math from introcs.stdlib import stdio number = [2**x for x in range(1, 11)] for n in number: stdio.write(f"{math.log2(n)}\t") stdio.write(f"{n}\t") stdio.write(f"{math.log(n, math.e)}\t") stdio.write(f"{math.pow(n, 2)}\t") stdio.write(f"{math.pow(n, 3)}\t") stdio.writeln(f"{math.pow(2, n)}")
import sys from introcs.stdlib import stdio stdio.write('HI, ') stdio.write(sys.argv[1]) stdio.writeln('. How are you?')
import random import sys from introcs.stdlib import stdarray, stdio m = int(sys.argv[1]) n = int(sys.argv[2]) perm = stdarray.create_1d(n, 0) for i in range(n): perm[i] = i for i in range(m): r = random.randrange(i, n) temp = perm[r] perm[r] = perm[i] perm[i] = temp for i in range(m): stdio.write(f"{perm[i]} ") stdio.writeln()
import sys from introcs.stdlib import stdio n = int(sys.argv[1]) v = 1 while v <= n // 2: v *= 2 while v > 0: if n < v: stdio.write(0) else: stdio.write(1) n -= v v //= 2 stdio.writeln()
import sys from introcs.stdlib import stdio n = int(sys.argv[1]) factor = 2 while factor * factor <= n: while (n % factor) == 0: n //= factor stdio.write(f"{factor} ") factor += 1 if n > 1: stdio.write(n) stdio.writeln()