ZOJ-1899

来源:互联网 发布:pdg2pdf mac 编辑:程序博客网 时间:2024/06/03 23:03

一时兴起用Python写了写,发现以前看过的书全忘光了,输入输出的格式坑死我了。。语法几乎每行都要google,写了半天终于拼出了份丑陋的代码,凑和着AC了

import sysdef print_tree():    if(not first):        print      keys = trees.keys();    keys.sort()    for key in keys:        print '%s %.4f' % (key, float(trees.get(key)) * 100 / total)stdin = sys.stdinline = stdin.readline()trees = dict()total = 0first = Truewhile(True):    if(not line):        break    elif(not line.strip()):          print_tree()        first = False        trees.clear()        total = 0    else:        total += 1        line = line.strip()        if(trees.has_key(line)):            trees[line] += 1        else:            trees[line] = 1    line = stdin.readline()        print_tree()


0 0
原创粉丝点击