zoukankan      html  css  js  c++  java
  • 杭电oj1282--回文数猜想

    回文数猜想

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 5575    Accepted Submission(s): 3352


    Problem Description
    一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的,这样的数就叫回文数。任取一个正整数,如果不是回文数,将该数与他的倒序数相加,若其和不是回文数,则重复上述步骤,一直到获得回文数为止。例如:68变成154(68+86),再变成605(154+451),最后变成1111(605+506),而1111是回文数。于是有数学家提出一个猜想:不论开始是什么正整数,在经过有限次正序数和倒序数相加的步骤后,都会得到一个回文数。至今为止还不知道这个猜想是对还是错。现在请你编程序验证之。
     

     

    Input
    每行一个正整数。
    特别说明:输入的数据保证中间结果小于2^31。
     

     

    Output
    对应每个输入,输出两行,一行是变换的次数,一行是变换的过程。
     

     

    Sample Input
    27228
    37649
     

     

    Sample Output
    3
    27228--->109500--->115401--->219912
    2
    37649--->132322--->355553
     

     

    Author
    SmallBeer(CML)
     

     

    Source
     

     

    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1279 1287 1256 1250 1230 
     
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    int main(){
        int n;
        int num[10], abc[10];
        while(~scanf("%d", &n){
            int One = n;
            int cnt = 0;
        s1:    int T = n; 
            int Q = 0;
            while(T){
                num[Q++] = T%10;
                T /= 10;    
            } 
            int sum = 0;
            for(int i = 0; i < Q; i++)
                sum = sum * 10 + num[i];
            if(sum == n){
                printf("%d
    ", cnt);
                printf("%d", One);
                for(int i = 0; i < cnt; i++)        
                    printf("--->%d", abc[i]);
                printf("
    ");
            }
            else{
                abc[cnt++] = sum + n;
                n = sum + n;
                goto s1;
            }
        }
        return 0;
    }
  • 相关阅读:
    SQLMAP注入教程-11种常见SQLMAP使用方法详解
    VS2012/2013/2015/Visual Studio 2017 关闭单击文件进行预览的功能
    解决 IIS 反向代理ARR URLREWRITE 设置后,不能跨域跳转 return Redirect 问题
    Spring Data JPA one to one 共享主键关联
    JHipster 问题集中
    Spring Data JPA 定义超类
    Spring Data JPA查询关联数据
    maven命名
    maven仓库
    Jackson读取列表
  • 原文地址:https://www.cnblogs.com/soTired/p/4763533.html
Copyright © 2011-2022 走看看