zoukankan      html  css  js  c++  java
  • HUNNU11352:Digit Solitaire

    Problem description
      

    Despite the glorious fall colors in the midwest, there is a great deal of time to spend while on a train from St. Louis to Chicago. On a recent trip, we passed some time with the following game.

    We start with a positive integer S. So long as it has more than one digit, we compute the product of its digits and repeat. For example, if starting with 95, we compute 9 × 5 = 45 . Since 45 has more than one digit, we compute 4 × 5 = 20 . Continuing with 20, we compute 2 × 0 = 0 . Having reached 0, which is a single-digit number, the game is over.

    As a second example, if we begin with 396, we get the following computations:
    3 × 9 × 6 = 162
    1 × 6 × 2 = 12
    1 × 2 = 2
    and we stop the game having reached 2.


    Input
       Each line contains a single integer 1 ≤ S ≤ 100000, designating the starting value. The value S will not have any leading zeros. A value of 0 designates the end of the input.
    Output
      For each nonzero input value, a single line of output should express the ordered sequence of values that are considered during the game, starting with the original value.
    Sample Input
    95
    396
    28
    4
    40
    0
    Sample Output

    95 45 20 0396 162 12 228 16 6440 0

    题意:给出一个数字,将每一位相乘得到下一个数字,知道数字位数为1则停止,输出所有情况

    水题,不解释

    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
        int n,t,r,s;
        while(~scanf("%d",&n),n)
        {
            int cnt = 0;
            printf("%d",n);
            if(n>=10)
            {
                while(n)
                {
                    t = n;
                    s = 1;
                    while(t)
                    {
                        r = t%10;
                        s*=r;
                        t/=10;
                    }
                    n = s;
                    if(n/10==0)
                    {
                        printf(" %d",n);
                        break;
                    }
                    printf(" %d",s);
                }
            }
            printf("
    ");
        }
    
        return 0;
    }
    
    


     

  • 相关阅读:
    网络流之对偶图转最短路
    BZOJ5418 NOI2018屠龙勇士EXCRT
    BZOJ1951 [Sdoi2010]古代猪文 NOIP数论大杂烩
    中国剩余定理及EX及单层EXLucas定理讲解
    网络流24题之负载平衡问题
    输入一个url到浏览器页面展示都经历了哪些过程
    前端部署dist包到服务器
    img标签显示 base64格式的 图片
    字符串用react 用sha256加密
    前端下载证书文件cer用后端返回的加密数据
  • 原文地址:https://www.cnblogs.com/riskyer/p/3291939.html
Copyright © 2011-2022 走看看