2017年大数据开发HuaWei笔试题两道(AC)

题目没存,后面找到后有机会补上,先附上代码占坑。


题1代码:

import sys
lists=sys.stdin.readline().strip().split('-')
li='0-670-82162'
lists=li.split('-')
if len(lists)!=3:
    print "ERROR"
lists1=lists

try:
    l1=len(lists[0])
    l2=len(lists[1])
    l3=len(lists[2])
    ll1=int(lists[0])
    ll2=int(lists[1])
    ll3=int(lists[2])
    if l1==1 and l2==3 and l3==5:
        string=''.join(lists1)
        length=len(string)
#        print string
        suma=0
        sum1=0
        for i in range(length):
            sum1 +=int(string[i])*(i+1)
        suma=sum1
        tt=suma//11
        if tt==10:
            tt='X'
        else:
            tt=tt-10
    lists.append(str(tt))
    print '-'.join(lists)        
except:
    print "ERROR2"

题2代码:

import sys
listsa1=sys.stdin.readline().strip()
if len(listsa1)!=11:
    print "ERROR"
else:
    lists=listsa1.split('-')
    if len(lists)!=3:
        print "ERROR"
    else:
        lists1=lists
        try:
            l1=len(lists[0])
            l2=len(lists[1])
            l3=len(lists[2])
            ll1=int(lists[0])
            ll2=int(lists[1])
            ll3=int(lists[2])
            if type(ll1) ==int or type(ll2)==int or type(ll3)==int:
                if l1==1 and l2==3 and l3==5:
                    string=''.join(lists1)
                    length=len(string)
                    suma=0
                    sum1=0
                    for i in range(length):
                        sum1 +=int(string[i])*(i+1)
                    suma=sum1
                    tt=suma%11
                    if tt==10:
                        tt='X'
#                    else:
#                        tt=tt-10
                    lists.append(str(tt))
                    print '-'.join(lists)
                else:
                    print "ERROR"
        except:
            print "ERROR"


你可能感兴趣的:(2017年大数据开发HuaWei笔试题两道(AC))