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. WinSock - 建立有连接的通信

    1.建立服务端(发送端) (1)声明成员变量 public: CSocket m_sockSend; (2)每隔一秒钟发送一次数据 2.建立客户端(接收端) (1)声明成员变量 public: CSo ...

  2. Oracle Autonomous Transactions(自治事务)

    Oracle Autonomous Transactions Autonomous transactions allow you to leave the context of the calling ...

  3. 移动开发中的Scheme跳转说明——Allowing OtherApps to Start Your Activity

    Allowing OtherApps to Start Your Activity 为了开发更多人使用的App,我们总希望我们的App能够提供一种接口被其他App调用.如我们常见的 大众点评  与  ...

  4. 为cocos2dx添加ndk库

    碰到很多坑: 1:引用库定义成include $(BUILD_SHARED_LIBRARY),结果生成了两个so文件,应该把库声明为BUILD_STATIC_LIBRARY 2:把库的java放到了项 ...

  5. C++ Primer 学习笔记_76_模板和泛型编程 --模板定义[继续]

    模板和泛型编程 --模板定义[续] 四.模板类型形參 类型形參由keywordclass或 typename后接说明符构成.在模板形參表中,这两个keyword具有同样的含义,都指出后面所接的名字表示 ...

  6. html中加入超链接方式的汇总

    在CSS样式中,对超链接的样式有以下几种定义(1)设置链接未被访问时的样式,具体写法如下:a:link{font-size:10px;... }(2)设置链接在鼠标经过时的样式,具体写法如下:a:ho ...

  7. My Emacs For Common Lisp

    My Emacs For Common Lisp My Emacs For Common Lisp

  8. lua的table库中经常使用的函数

    lua提供了一些辅助函数来操作table. 比如,从list中insert和remove元素,对array的元素进行sort.或者concatenate数组中的全部strings.以下就具体地解说这些 ...

  9. nginx源代码分析--高性能server开发 常见的流程模型

    1.高性能server 对于高性能server对于.处理速度和占用空间小是典型特性.特别是当server经验C10K问题的时候(网络server在处理数以万计的client连接时.往往出现效率低下甚至 ...

  10. 使用模板类导致error LNK2019: 无法解析的外部符号

    原地址 1.定义模板类: template<class T> class Stack {....}; 2.定义模板成员函数: 每个函数头都要以相同的模板声明打头,并将类限定符改成:类名&l ...