U E D R , A S I H C RSS

Jolly Jumpers/남훈

주책.. 심심해설



import sys

def initTable(n):
    return [0] * (n-1)

def check(table, diff):
    if diff <= len(table):
        table[diff - 1] = 1

def isComplete(table):
    if table == []:
        return True
    if table[0] == 0:
        return False
    return isComplete(table[1:])

def isJolly(seq):
    n = len(seq)
    diffTable = initTable(n)

    for i in range(n-1):
        diff = abs(seq[i] - seq[i+1])
        check(diffTable, diff)

    if isComplete(diffTable):
        return True
    else:
        return False

def parseInput():
    lines = []

    while 1:
        line = sys.stdin.readline()
        if line == '' or line[0] == '0':
            break

        line = line.rstrip().split(' ')
        inted = []

        for atom in line:
            inted.append(int(atom))

        lines.append(inted[1:])
	
    return lines

def displayDecision(t):
    if t:
        print 'Jolly'
    else:
        print 'Not jolly'

def main():
    lines = parseInput()

	##debug
    #print lines

    for line in lines:
        displayDecision(isJolly(line))

    return 0

if __name__ == '__main__':
    main()


파이썬 쓰면 반칙?

  • 언어는 상관없을걸요?? 짱+_+b - 지원

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:34
Processing time 0.0125 sec