Py||Count down

题目描述
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)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值