超越数

chaoyueshu

Study More Problems; Talk Less of Isms.
  • English
  • 中文
  • Home
  • Contributions
  • Programs
    • Tiary - Diary Keeper (C++)
    • Pig Latin Translator (PHP)
    • Chinese ID Calc (Python)
  • Digests »
    • Digests
    • Quotes
    • Git 中文教程
    • 诗经·国风
    • Study More Problems; Talk Less of Isms
    • 郑渊洁:请让孩子输在起跑线上
    • Sewing machine
  • FAQ

No info in English. Just RTFC and you’re gonna understand :)

#!/usr/bin/python

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.

"""
Given the first 17 digits, calculate the last digit of an
18-digit Chinese ID (second-generation ID) number
"""

import sys,re

pattern = re.compile(r'^\d{17}$')
err = 0

for x in sys.argv[1:]:
    if not pattern.match(x):
        sys.stderr.write ('Error: {0}\n'.format(x))
        err = 1
        continue
    n = sum(map(lambda a,b:a*(ord(b)-ord('0')), \
            (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2), x)) % 11
    print (x+'10X98765432'[n])
sys.exit(err)
Creative Commons License Valid XHTML 1.0 Strict Valid CSS!