#!/bin/env python # coding:utf-8 import sys Input = [] while True: line = sys.stdin.readline() if not line: break Input.extend(line.split()) In = list(str(int(Input[0])+1)) if len(In) % 2 == 1: Mi = len(In) / 2 for i in xrange(1, Mi+1): if int(In[Mi+i]) > int(In[Mi-i]): #前半部分的加一(考虑中位是9),逆序拼接 Mi_int = int(''.join(In[:Mi+1])) + 1 In = list(str(Mi_int)) In.extend(In[:-1][::-1]) break elif In[Mi+i] < In[Mi-i]: #直接对半拼接 In = In[:Mi+1] In.extend(In[:-1][::-1]) break else: #组成奇数位,方便比较 In.insert(len(In)/2, '#') Mi = len(In) / 2 for i in xrange(1,Mi+1): if In[Mi+i] > In[Mi-i]: Mi_int = int(''.join(In[:Mi])) + 1 In = list(str(Mi_int)) In.extend(In[::-1]) break else: In = In[:Mi] In.extend(In[::-1]) break print ''.join(In)
点赞 评论

相关推荐

kyw_:接好运
点赞 评论 收藏
分享
牛客网
牛客企业服务