参加了2012年的GCJ ,感觉自己比去年有进步或者google比去年有放水,总之我是过了资格赛。
第一题相对简单,根据已经给出的例子,拿程序跑一遍得出26个字母+空格对应的密文的相应字母,看看结果是否符合题目说明:
- google = ['y qee ejp mysljylc kd kxveddknmc re jsicpdrysi',
- 'rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd',
- 'de kr kd eoya kw aej tysr re ujdr lkgc jv']
- nature = ['a zoo our language is impossible to understand',
- 'there are twenty six factorial possibilities',
- 'so it is okay if you want to just give up']
- alphabet = 'abcdefghijklmnopqrstuvwxyz '
- mapping = {}
- for letter in alphabet:
- mapping[letter] = set()
- for i in range(len(google)):
- for j in range(len(google[i])):
- mapping[google[i][j]].add( nature[i][j] )
- print(mapping)
output: {' ': {' '}, 'a': {'y'}, 'c': {'e'}, 'b': {'h'}, 'e': {'o'}, 'd': {'s'}, 'g': {'v'},
'f': {'c'}, 'i': {'d'}, 'h': {'x'}, 'k': {'i'}, 'j': {'u'}, 'm': {'l'}, 'l': {'g'}, 'o': {'k'},
'n': {'b'}, 'q': {'z'}, 'p': {'r'}, 's': {'n'}, 'r': {'t'}, 'u': {'j'}, 't': {'w'}, 'w': {'f'},
'v': {'p'}, 'y': {'a'}, 'x': {'m'}, 'z': set()}
发现z字母没有对应,检查发现应该对应:q
然后把上面set() 结构换成字符 '' ,跑一遍程序得出映射表:
mapping = {' ': ' ', 'a': 'y', 'c': 'e', 'b': 'h', 'e': 'o', 'd': 's', 'g': 'v', 'f': 'c', 'i': 'd', 'h': 'x', 'k': 'i', 'j': 'u', 'm': 'l', 'l': 'g', 'o': 'k', 'n': 'b', 'p': 'r', 's': 'n', 'r': 't', 'u': 'j', 't': 'w', 'w': 'f', 'v': 'p', 'y': 'a', 'x': 'm', 'q': 'z', 'z': 'q'}
之后就是做翻译的过程,google的contest Analysis:
- for tc in xrange(1, int(raw_input()) + 1):
- english = ''.join(
- [mapping[ch] for ch in raw_input()])
- print 'Case #%d: %s' % (tc, english)
阅读(1619) | 评论(0) | 转发(0) |