• 1136 A Delayed Palindrome


    Consider a positive integer N written in standard notation with k+1 digits ai​ as ak​⋯a1​a0​ with 0≤ai​<10 for all i and ak​>0. Then N is palindromic if and only if ai​=ak−i​ for all i. Zero is written 0 and is also palindromic by definition.

    Non-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic number is reversed and the result is added to the original number. If the result is not a palindromic number, this is repeated until it gives a palindromic number. Such number is called a delayed palindrome. (Quoted from https://en.wikipedia.org/wiki/Palindromic_number )

    Given any positive integer, you are supposed to find its paired palindromic number.

    Input Specification:

    Each input file contains one test case which gives a positive integer no more than 1000 digits.

    Output Specification:

    For each test case, print line by line the process of finding the palindromic number. The format of each line is the following:

    A + B = C
    

    where A is the original number, B is the reversed A, and C is their sum. A starts being the input number, and this process ends until C becomes a palindromic number -- in this case we print in the last line C is a palindromic number.; or if a palindromic number cannot be found in 10 iterations, print Not found in 10 iterations. instead.

    Sample Input 1:

    97152
    

    Sample Output 1:

    1. 97152 + 25179 = 122331
    2. 122331 + 133221 = 255552
    3. 255552 is a palindromic number.

    Sample Input 2:

    196
    

    Sample Output 2:

    1. 196 + 691 = 887
    2. 887 + 788 = 1675
    3. 1675 + 5761 = 7436
    4. 7436 + 6347 = 13783
    5. 13783 + 38731 = 52514
    6. 52514 + 41525 = 94039
    7. 94039 + 93049 = 187088
    8. 187088 + 880781 = 1067869
    9. 1067869 + 9687601 = 10755470
    10. 10755470 + 07455701 = 18211171
    11. Not found in 10 iterations.

    高精加模拟: 

    1. #include
    2. #include
    3. #include
    4. #include
    5. using namespace std;
    6. bool check(string x) {
    7. int i = 0;
    8. while (x[i] == '0') {
    9. i++;
    10. }
    11. for (int j = 0; i < x.size(); i++, j++) {
    12. if (x[i] != x[x.size() - 1 - j]) {
    13. return false;
    14. }
    15. }
    16. return true;
    17. }
    18. int main() {
    19. int cnt = 0;
    20. string n;
    21. cin >> n;
    22. while (!check(n) && cnt < 10) {
    23. cnt++;
    24. string t = n, s = "";
    25. reverse(t.begin(), t.end());
    26. int x, y = 0;
    27. for (int i = n.size() - 1; i >= 0; i--) {
    28. x = (n[i] - '0' + t[i] - '0' + y) % 10;
    29. s += (x + '0');
    30. y = (n[i] - '0' + t[i] - '0' + y) / 10;
    31. }
    32. if (y) {
    33. s += (y + '0');
    34. }
    35. reverse(s.begin(), s.end());
    36. int i = 0;
    37. while (s[i] == '0') {
    38. i++;
    39. }
    40. if (i) {
    41. s.erase(0, i);
    42. }
    43. cout << n << " + " << t << " = " << s << endl;
    44. n = s;
    45. }
    46. if (cnt >= 10) {
    47. cout << "Not found in 10 iterations.";
    48. } else {
    49. cout << n << " is a palindromic number.";
    50. }
    51. return 0;
    52. }
  • 相关阅读:
    数据结构的结构复杂度你了解么
    Java SPI的本质
    【Mysql-索引的底层结构】
    java EE初阶 — 线程的状态
    HTML+CSS制作简单的家乡网页 ——我的家乡介绍广东 web前端期末大作业
    链式法则:概率论描述语言模型
    弘辽科技:拼多多权重怎么补?怎么修复权重?
    【渗透测试】Apache Shiro系列漏洞
    ArcGIS中的Excel to table等工具无法输出结果
    演讲比赛流程管理系统(看看你的星座会赢吗)
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/127959077