• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Warm up 14 [B] Digit Solitaire

Digit Solitaire
Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB
Total submit users: 55, Accepted users: 55
Problem 12759 : No special judgement
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 0
396 162 12 2
28 16 6
4
40 0
Problem Source
mcpc 2012
 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cstdio>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define maxn 450005
12 #define ll long long
13 #define INF 0x7fffffff
14 char str[100001];
15 int n, m;
16 double ans;
17 int a[maxn];
18 int fun(int s){
19     int i = 0;
20     while (s >= 10){
21         printf("%d ", s);
22         int x = s;
23         s = 1;
24         while (x){
25             s =s* (x % 10);
26             x /= 10;
27         }
28     }
29     return s;
30 }
31 int main(){
32     int cas = 1;
33     while (~scanf("%d", &n)&&n){
34         printf("%d\n", fun(n));
35     }
36     return 0;
37 }
View Code
posted @ 2013-10-27 22:21  HaibaraAi  阅读(125)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3