• 回文数猜想(与6174问题很像)


    #include<stdio.h>
    #include<string.h>
    char s[20];
    int is_prime(int x)
    {
        int n;
        sprintf(s,"%d",x);
        n=strlen(s);
        for(int i=0;i<=n/2;i++)
            if(s[i]!=s[n-i-1])
            return 0;
        return 1;
    }
    int get_next(int x)
    {
        int n,y;
        sprintf(s,"%d",x);
        n=strlen(s);
        for(int i=0;i<n/2;i++)
        {
            char t=s[i];s[i]=s[n-i-1];s[n-i-1]=t;
        }
        sscanf(s,"%d",&y);
        return x+y;
    }
    int num[2000];
    int main()
    {
        int cnt;
        while(scanf("%d",&num[0])!=EOF)
        {
            int first=1;
            cnt=1;
            for(;;)
            {
                int found=0,i,j;
                num[cnt]=get_next(num[cnt-1]);
                 for(i=1;i<=cnt;i++)
                    {
                        if(is_prime(num[i]))
                       {
                           found=1;
                           printf("%d
    ",i);
                           break;
                       }
    
                    }
                    if(found)
                    {
                         for(j=0;j<=i;j++)
                           {
                               if(first)
                                 first=0;
                              else
                              printf("--->");
                             printf("%d",num[j]);
                           }
                          break;
                    }
    
                cnt++;
            }
            printf("
    ");
    
        }
        return 0;
    }
    
  • 相关阅读:
    Gateway网关
    SSO单点登录
    Hystrix断路器
    MySql 55题
    1、两数之和
    面试题 17.13、恢复空格
    OpenFeign
    Cookie和Session简介
    2、两数相加
    Ribbon 负载均衡
  • 原文地址:https://www.cnblogs.com/lyf123456/p/3219160.html
Copyright © 2020-2023  润新知