Py||Count down

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Lhw_666/article/details/102738964

题目描述
Mike is a clever boy. Today, Mike’s teacher gave him an assignment:

The teacher gave Mike a few cards, each card has two numbers, then the teacher asked Mike to look at the card, and asked him look at the card backwards. Then according the law of numbers (increment or decrement), guess what the next inverted number.

For example:
(6 looking backwards is 9)
(8 looking backwards is 8)
(89 looking backwards is 68)

And then we have a card with two number: 88 and 68, they looking backwards are 88 and 89, so the next number is 90, but it is not the right answer. 06 is right one because of 90 looking backwards is 06.
输入
The input consists of two lines.
The first line is the integer n (n>=2), and the second line is n consecutive integers a1, a2…an (less than 100).
They are two positive numbers, consisting only of 0, 1, 6, 8, and 9, which means that when you look number on the card backwards, such as 68 is actually 89.
输出
Output the next inverted integer.
样例输入 Copy
2
88 68
样例输出 Copy
06

la=int(input())
lc=[]
lb=input()
y=0
k=0
for i in range(len(lb)):
    if(lb[i]==' 'or i==len(lb)-1):
        if(k==0):
            y=0
        else:
            y=k+1
        if(i==len(lb)-1):
            k=i+1
        else:
            k=i
        for j in range(k-1,y-1,-1):
            if(lb[j]=='0'):
                lc.append('0')
            elif(lb[j]=='1'):
                lc.append('1')
            elif(lb[j]=='6'):
                lc.append('9')
            elif(lb[j]=='8'):
                lc.append('8')
            elif(lb[j]=='9'):
                lc.append('6')
        lc.append(' ')

d=''.join(lc)
e=[int(n) for n in d.split()]
f=(e[len(e)-1]-e[0])/(len(e)-1)
g=int(f)+e[len(e)-1]
h=str(g)
m=[]
for j in range(len(h)-1,-1,-1):
    if(h[j]=='0'):
        m.append('0')
    elif(h[j]=='1'):
        m.append('1')
    elif(h[j]=='6'):
        m.append('9')
    elif(h[j]=='8'):
        m.append('8')
    elif(h[j]=='9'):
        m.append('6')
n=''.join(m)
print(n)

猜你喜欢

转载自blog.csdn.net/Lhw_666/article/details/102738964
今日推荐