• HDU1282回文数猜想



    代码:
    #include<iostream> 
    #include<cstring> 
    using namespace std; 
    int main(void

        char snumber[1001],snumber1[1001],snumber2[1001],answer[1001][1001]; 
        int len1,flag,a,k,i,j; 
        while(cin>>snumber) 
        { 
            strcpy(snumber1,snumber); 
            strrev(snumber1);//将数字倒置 
            j=1
            strcpy(answer[0],snumber); 
            //大数相加,再加上点处理 
            while(strcmp(snumber,snumber1)) 
            { 
                k=1
                len1=strlen(snumber); 
                a=snumber[0]-'0'
                memset(snumber2,0,sizeof(snumber2)); 
                for(i=0;i<len1;i++) 
                    snumber2[k++]=snumber[i]+snumber1[i]-'0'
                 
                for(i=len1;i>=2;i--) 
                { 
                    if(snumber2[i]>'9'
                    { 
                        snumber2[i]-=10
                        snumber2[i-1]++; 
                    } 
                } 
                flag=0
                if(snumber2[1]>'9'
                { 
                    snumber2[1]-=10
                    snumber2[0]='1'
                    flag=1
                } 
                memset(snumber,0,sizeof(snumber)); 
                if(!flag) 
                    for(i=0;i<len1;i++) 
                    { 
                        snumber[i]=snumber2[i+1];     
                    } 
                else 
                    for(i=0;i<=len1;i++) 
                    { 
                        snumber[i]=snumber2[i]; 
                    } 
                strcpy(answer[j++],snumber); 
                strcpy(snumber1,snumber); 
                strrev(snumber1); 
            } 
            cout<<j-1<<endl; 
            for(i=0;i<j-1;i++) 
                cout<<answer[i]<<"--->"
            cout<<answer[j-1]; 
            cout<<endl; 
        } 
        return 0

  • 相关阅读:
    【R】如何去掉数据框中包含非数值的行?
    解读NoSQL数据库的四大家族
    MapReduce
    从网站上扒网页,保存为file文件格式
    jfinal 模板引擎
    pycharm的版本对应问题
    AttributeError: module 'DBBase' has no attribute 'DBBase'
    四则运算 python
    用命令行去运行程序
    Pandas入门CNV.TXT数据分析
  • 原文地址:https://www.cnblogs.com/cchun/p/2520143.html
Copyright © 2020-2023  润新知