コード例 #1
0
def main():
    n = 5
    p = 0.5
    trials = 2000

    q = evaluate(n,p,trials)
    stdio.writeln(q)
コード例 #2
0
def main():
    print('please input your information:')
    s = stdio.readLine().strip('/n')
    entropy_sum = 0.0


    entropy_sum =count_entropy(s)

    stdio.writeln('The engropy of "{0}" is {1}'.format(s,entropy_sum))
コード例 #3
0
def main():

    # r_obj = __redirection__()
    # sys.stdout = r_obj
    n = int(sys.argv[1])
    total = 0
    for i in range(n):
        total += stdio.readInt()
    stdio.writeln('in {0} sum is'.format(sys.argv[0]) + str(total))
コード例 #4
0
def main():
    r1 = int(sys.argv[1])
    g1 = int(sys.argv[2])
    b1 = int(sys.argv[3])
    r2 = int(sys.argv[4])
    g2 = int(sys.argv[5])
    b2 = int(sys.argv[6])
    c1 = Color(r1,g1,b1)
    c2 = Color(r2,g2,b2)

    stdio.writeln(areCompatible(c1,c2))
コード例 #5
0
def main():
    n = int(sys.argv[1])

    total1 = 0.0
    watch1 = stopwatch()
    for i in range(n):
        total1 += i**2

    time1 = watch1.elapsedTime()

    total2 = 0.0
    watch2 = stopwatch()
    for i in range(n):
        total2 += i * i
    time2 = watch2.elapsedTime()

    stdio.writeln(total1 / total2)
    stdio.writeln(time1 / time2)
コード例 #6
0
def write1D(a):
    """
    Write array a to sys.stdout.  First write its length. bool objects
    are written as 0 and 1, not False and True.
    """
    length = len(a)
    stdio.writeln(length)
    for i in range(length):
        # stdio.writef('%9.5f ', a[i])
        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()
コード例 #7
0
def write2D(a):
    """
    Write two-dimensional array a to sys.stdout.  First write its
    dimensions. bool objects are written as 0 and 1, not False and True.
    """
    rowCount = len(a)
    colCount = len(a[0])
    stdio.writeln(str(rowCount) + ' ' + str(colCount))
    for row in range(rowCount):
        for col in range(colCount):
            #stdio.writef('%9.5f ', a[row][col])
            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()
コード例 #8
0
命令行模式:
python3 tansition.py<tiny.txt|python3 markov.py 20
'''

from stdpackage import stdio,stdarray
import sys

moves = int(sys.argv[1])
n = stdio.readInt()
stdio.readInt()

p = stdarray.create2D(n,n,0.0)
for i in range(n):
    for j in range(n):
        p[i][j] = stdio.readFloat()

ranks = stdarray.create1D(n,0.0)

ranks[0] = 1.0
for i in range(moves):
    new_ranks = stdarray.create1D(n,0.0)
    for k in range(n):
        for j in range(n):
         new_ranks[j] += ranks[k]*p[k][j]
    ranks = new_ranks

for i in range(n):
    stdio.writef('%8.5f',ranks[i])
stdio.writeln()

コード例 #9
0
ファイル: tansition.py プロジェクト: miaozaiye/PythonLearning
#计算输出转换矩阵,矩阵上第i行第j列的数字,代表从i页跳转到 j页的概率

from stdpackage import stdarray, stdio

n = stdio.readInt()

linkCounts = stdarray.create2D(n, n, 0)
outDegress = stdarray.create1D(n, 0)

while not stdio.isEmpty():
    i = stdio.readInt()

    j = stdio.readInt()
    outDegress[i] += 1
    linkCounts[i][j] += 1

stdio.writeln(str(n) + ' ' + str(n))

for i in range(n):
    for j in range(n):
        p = (0.8 * linkCounts[i][j] / outDegress[i]) + (0.2 / n)
        stdio.writef('%8.5f', p)
    stdio.writeln()
コード例 #10
0
def main():
    isOpen = stdarray.readBool2D()
    stdarray.write2D(flow(isOpen))
    stdio.writeln(percolates(isOpen))
コード例 #11
0
def main():
    instream = InStream(sys.argv[1])
    a = instream.readAllStrings()
    while not stdio.isEmpty():
        key = stdio.readString()
        if search(key, a) < 0: stdio.writeln(key)