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()函数;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值