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. JSTL解析——005——core标签库04

    直接入主题,标签讲解 1.<c:import>标签 JSP里面有<% file include="XX"%> 与<jsp:include>,JS ...

  2. JavaScript闭包(closure)入门: 拿"开发部"和"技术牛"举个例子

    虽然只是一小段菜鸟的学习笔记 , 不过还是希望看到的高手看到不足的时候帮忙指点~ 一:代码和执行过程 /** * http://blog.csdn.net/ruantao1989 * ==>Ju ...

  3. Android学习路线(二十四)ActionBar Fragment运用最佳实践

    转载请注明出处:http://blog.csdn.net/sweetvvck/article/details/38645297 通过前面的几篇博客.大家看到了Google是怎样解释action bar ...

  4. Java Design Demo -简单的队列-异步多任务队列(java android)

    简单的单线程队列 -- 工作的时候遇到劣质打印机.给打印机发消息,打印机就会打印,如果在打印机还在打印的时候,就 再发消息打印,就会出现消息丢失.所以需要给上一个任务一些处理的间隔时间. 单线程的消息 ...

  5. MFC 用gdi绘制填充多边形区域

    MFC 用gdi绘制填充多边形区域 这里的代码是实现一个三角形的绘制,并用刷子填充颜色 在OnPaint()函数里面 运用的是给定的三角形的三个点,很多个点可以绘制多边形 CBrush br(RGB( ...

  6. ThinkPHP 3 的CURD管理用户信息 修改和删除

    本节课大纲: 一.ThinkPHP 3 的CURD管理用户信息 http://localhost:8080/thinkphp/index.php/User/index 访问User类的index方法 ...

  7. Android CTS 结果 testResult.xml 修改 fail 项 为 notExecuted 项 分析

    这两天一直在搞 Android 4.1 CTS ,每次完整跑完一遍后总有几百项 failed,用编辑器手动改为 notExecuted 项后重新跑,有很多项第二次都跑过了. 但是发现直接修改也带来很多 ...

  8. js基础语法(一)

    学习网站参考:http://www.w3school.com.cn/ 写入html输出: document.write('test out put'); 例子: http://www.w3school ...

  9. Indy的TCPServer到底能支持多少个连接

    最近一个项目,最开始使用IdTcpServer,在大压力测试的时候,只连接了800个多一点的客户端(每个客户端连接上之后每秒钟发送一个几十字节的报文,服务器应答).但是持续的时间不会超过10分钟,服务 ...

  10. linux文件夹介绍

    (1)documentation 这个文件夹下没有内核代码,仅仅有一套实用的文档,但这些文档的质量不一.比如内核文档的文件系统,在该文件夹下有相当优秀并且相当完整的文档:而另外一部分内核,比如进程调度 ...