在C ++中这将是最快的逻辑来找到一个给定的15位数字回文旁边?例如,这将是下一个回文:134567329807541
in c++ what will be the fastest logic to find next palindrome of a given 15 digit number? for example what will be the next palindrome of: 134567329807541 ?
分割数为三个部分,头
,中期
,尾
1345673 2 9807541
1345673 2 9807541
逆向头
,并将其与尾
3765431
Reverse head
and compare it to tail
3765431
如果反向(头)LT =尾部
(如果他们是平等的初始输入是一个回文,并且希望下一个)
If reverse(head) <= tail
( if they are equal the initial input is a palindrome, and you want the next )
中期&LT; 9
,年年递增
否则增量头
部分,并设置中期:= 0
If mid < 9
, increment mid
Else increment head
part and set mid := 0
结果:= 头反向中期(头)
1345673 3反向(1345673)=> 134567333765431
1345673 3 reverse(1345673) => 134567333765431