全部评论
找比当前数小的最大值?
一直百分之30
import sys
a = sys.stdin.readline().strip()
r = []
for c in a:
r.append(int(c))
flag = True
for i in range(len(r)-1):
if r[i] > r[i+1]:
flag = False
if flag:
print("0")
sys.exit(0)
right_index = len(r) - 1
# mid_index = -1
left_index = -1
# print(r)
for i in range(len(r)-1, 0, -1):
if r[i] < r[i-1]:
left_index = i-1
break
for i in range(len(r)-1, left_index, -1):
if r[i] < r[left_index]:
right_index = i
break
r[left_index], r[right_index] = r[right_index], r[left_index]
rr = r[:left_index+1]
if rr[0] == 0:
print("0")
sys.exit(0)
for i in reversed(r[left_index+1:]):
rr.append(i)
print("".join(map(lambda x:str(x), rr)))
大佬们,第一题我一直60%是为什么,求解答,是reverse超时了? string int64tostring(long long num)
{
string s1;
int count = 0;
while (num) {
if(count == 3)
{
s1.push_back(',');
count = 0;
}
char i = num%10+'0';
num = num/10;
s1.push_back(i);
count++;
}
reverse(s1.begin(), s1.end());
return s1;
}
相关推荐