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("\n");
} return 0;
}

HUNNU11352:Digit Solitaire的更多相关文章

  1. 四校训练 warm up 14

    A:Pythagoras's Revenge 代码: #include<cstdio> #define ll long long using namespace std; int main ...

  2. [LeetCode] Nth Digit 第N位

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  3. [LeetCode] Number of Digit One 数字1的个数

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  4. [Leetcode] Number of Digit Ones

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  5. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  6. kaggle实战记录 =>Digit Recognizer

    date:2016-09-13 今天开始注册了kaggle,从digit recognizer开始学习, 由于是第一个案例对于整个流程目前我还不够了解,首先了解大神是怎么运行怎么构思,然后模仿.这样的 ...

  7. [UCSD白板题] The Last Digit of a Large Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  8. Last non-zero Digit in N!(阶乘最后非0位)

    Last non-zero Digit in N! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  9. POJ3187Backward Digit Sums[杨辉三角]

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6350   Accepted: 36 ...

随机推荐

  1. Cocos2dx中Plugin-X 在android下的整合

    直接拉plugin-x中的jar包导入到Eclipse中就可以.用这么麻烦的工具干嘛.

  2. 设定十分钟android在状态栏上集成的开源project推荐

    1.前言 于android kitkat 有一个新功能可以设置背景的手机状态栏,让手机风的整个界面格是一致的,它看起来非常酷,在今年的google i/o向上android l这样的风格.来如今看我们 ...

  3. 用C++设计一个不能被继承的类(用私有构造函数+友元函数)

    题目:用C++设计一个不能被继承的类. 分析:这是Adobe公司2007年校园招聘的最新笔试题.这道题除了考察应聘者的C++基本功底外,还能考察反应能力,是一道很好的题目. 在Java中定义了关键字f ...

  4. 验证码 Captcha 之大插件

    验证码 Captcha 之大插件小用 不知何年何月才能完成OADemo啊,总之还是一步一步来吧,这段时间开始着手了,先做登陆.  前段时间研究了一下在CentOS7下安装Mysql和Memcached ...

  5. zoj 3870

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5518 题意:n个数,从中选出两个数,问这两个数的异或值大于两个数较大 ...

  6. 看来IT技术与军事技术都是相通的——都是对新事物极为敏感的领域

    这是读到这段时候的感想: 和海军中那些狂热的相信“皇军不可战胜”的大舰巨炮主义者们不同,山口对于与美国开战的主张是持坚定的反对态度的,和山本五十六都做过日本驻美武官的山口都认为一旦与美开战,日本或许能 ...

  7. What is tradebit?

    The Tradebit Fact Sheet What is tradebit?

  8. About VirtualBoxImages.com

    About VirtualBoxImages.com | VirtualBoxImages.com About VirtualBoxImages.com About: VirtualBoxImages ...

  9. Spring的datasource配置详解

    一句话,Spring对Hibernate的整合,是在applicationContext.xml中配置sessionFactory来实现的,其中sessionFactory中要装配dataSource ...

  10. <Win32_17>集音频和视频播放功能于一身的简易播放器

    前段时间,在学习中科院杨老师的教学视频时,他说了一句话: "我很反对百八十行的教学程序,要来就来一个完整的程序" 对此,我很是赞同.所谓真刀真枪的做了,你才会发现其中的奥秘——然而 ...