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. Flume 1.5日志收集和存款mongodb安装结构

    Flume该演示是不是说.你可以自己搜索. 但现在的互联网主要是Flume 1.4前版本号的信息.Flume 1.5在轰动的大变化.假设你准备尝试,我在这里给大家介绍一下程序最小化结构,和使用Mong ...

  2. 选择屏幕中的下拉框和dialog中下拉框设计

    REPORT  YTEST014. PARAMETERS: auart LIKE vapma-auart  AS LISTBOX   VISIBLE LENGTH 6. AT SELECTION-SC ...

  3. Webcast / 技术小视频制作方法——自己动手录制video轻松搞定

    Webcast / 技术小视频制作方法——自己动手录制video轻松搞定 http://blog.sina.com.cn/s/blog_67d387490100wdnh.html 最近申请加入MSP的 ...

  4. Delphi中使用GDI+进行绘图(2)

    2)使用IGDIPlus接口 (1)下载安装所需软件 可以在以下地址下载IGDI+最新的安装程序. http://www.mitov.com/products/igdi+ www.igdiplus.o ...

  5. [Codecademy] HTML&CSS 第一课:HTML Basic

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

  6. 为HttpStatusCodeResult加入customErrors

    asp.net mvc的action返回值为HttpStatusCodeResult时的customErrors总是不起作用 (404和exception时的500,因为他们并不是HttpStatus ...

  7. HttpWeb服务器之--用OO方式写

    虽然写的不是很好,但 最终解释权以及版权归13东倍所有! package com.web; import java.io.IOException; public class Test { public ...

  8. 注解框架---AndroidAnnotations

    AndroidAnnotations是一个开源框架,旨在加快Android开发的效率.通过使用它开放出来的注解api,你差点儿可以使用在不论什么地方, 大大的降低了无关痛痒的代码量,让开发人员可以抽身 ...

  9. Indy的评价

    已经抛弃了indy,实在是不好,tcp在android下退出报错.我现在改用系统自带的httpclient.推荐RTC RTC带有一个tcp组件,不过处理方式跟indy不同,测试过,在android下 ...

  10. C++的for循环细节,必看!

    C++中.For(A;B;C)   C语句是在每次循环后才运行. 如: y=10; for( i=0;i<10;y=++i) {    cout<<y<<endl; } ...