LA 2889 回文(找规律)

#include <string>
#include <iostream>
using namespace std;
int n;
int main()
{
    while (cin >> n && n)
    {
        long long x = 0;
        while (n > x * 2) x = x * 10 + 9;
        bool flag = 0;
        if (n > x + x / 10) flag = 1;
        n -= (flag ? x : x / 10);
        string str = to_string(n);
        string kstr(str.rbegin(), str.rend());
        if (flag) str += kstr;
        else str += kstr.substr(1, str.length() - 1);
        cout << str << endl;
    }
    return 0;
}



打表找规律


第1到100:

1
2
3
4
5
6
7
8
9
11
22
33
44
55
66
77
88
99
101
111
121
131
141
151
161
171
181
191
202
212
222
232
242
252
262
272
282
292
303
313
323
333
343
353
363
373
383
393
404
414
424
434
444
454
464
474
484
494
505
515
525
535
545
555
565
575
585
595
606
616
626
636
646
656
666
676
686
696
707
717
727
737
747
757
767
777
787
797
808
818
828
838
848
858
868
878
888
898
909
919



本地运行需要编译选项"-lcrypt"加持,否则需重写to_string()函数;


你可能感兴趣的:(LA 2889 回文(找规律))