주책.. 심심해설
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()