版本2和3间的区别
于2009-12-31 00:45:37修订的的版本2
大小: 670
编辑: czk
备注:
于2009-12-31 00:48:20修订的的版本3
大小: 993
编辑: czk
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 30: 行号 30:

wordscounter.py
{{{#!python


words = {}
try:
    while True:
        s = raw_input()
        if not s:
            continue
        if s in words:
            words[s]+=1
        else:
            words[s]=1
except EOFError:
    for i in sorted(words.keys()):
        print "%s %d" % (i, words[i])
}}}

test.py

   1 def store():
   2     n=raw_input()
   3     sum1=0
   4     for i in range(len(n)):
   5         sum1=sum1 + int(n[i])
   6     t=sum1%3
   7     if(t==0):
   8         print 2
   9     else:
  10         if(t==2):
  11            print 1
  12            print 2
  13         else:
  14            print 1
  15            print 1
  16 store()

test2.py

   1 def queens (row, col):
   2     def safe (ran, rst):
   3         def check (pos):
   4             return ran != rst[pos] and abs(ran - rst[pos]) != pos + 1
   5         return all([check(pos) for pos in range(len(rst))])
   6     return [[]] if col == 0 else [[ran] + rst for ran in range(row) for rst in queens(row, col - 1) if safe(ran, rst)]

wordscounter.py

   1 words = {}
   2 try:
   3     while True:
   4         s = raw_input()
   5         if not s:
   6             continue
   7         if s in words:
   8             words[s]+=1
   9         else:
  10             words[s]=1
  11 except EOFError:
  12     for i in sorted(words.keys()):
  13         print "%s %d" % (i, words[i])

Python代码片段 (2020-03-31 16:55:59由czk编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.