SRM147 DIV2 250

一般编程题

 1 import unittest
 2 
 3 class CCipher:
 4     def decode(self, cipherText, shift):
 5         s = ''
 6         for ch in cipherText:
 7             num = ord('A') + (ord(ch)-ord('A')+26-shift) % 26
 8             s += chr(num)
 9         return s
10 
11 
12 # test
13 o = CCipher()
14 t = unittest.TestCase()
15 
16 
17 # test case
18 t.assertEqual(o.decode("VQREQFGT", 2), "TOPCODER")
19 t.assertEqual(o.decode("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 10), "QRSTUVWXYZABCDEFGHIJKLMNOP")
20 t.assertEqual(o.decode("TOPCODER", 0), "TOPCODER")
21 t.assertEqual(o.decode("ZWBGLZ", 25), "AXCHMA")
View Code

 

posted @ 2013-11-27 09:02  valaxy  阅读(115)  评论(0编辑  收藏  举报