예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
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()
예제 #4
0
from introcs.stdlib import stdio

for i in range(1000, 2000):
    stdio.write(f"{i} ")
    if (i % 5) == 0:
        stdio.writeln()
예제 #5
0
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)}")
예제 #6
0
import sys
from introcs.stdlib import stdio

stdio.write('HI, ')
stdio.write(sys.argv[1])
stdio.writeln('. How are you?')
예제 #7
0
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()
예제 #8
0
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()
예제 #9
0
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()