TOJ 3534.Shift Number

题目链接:http://acm.tju.edu.cn/toj/showp3534.html


3534.    Shift Number
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 293    Accepted Runs: 131



If a number is the sum of an integer's several shifting forms, it is called the Shift Number.

For example, by shifting 123 four times and adding the four numbers together, we get 136653, which is a Shift Number. However, a shift number may be the sum of more than one integer's shifting forms. Such as, 45177 is a Shift Number, which could be generated from both 407 and 4107.

123 + 1230 + 12300 + 123000 = 136653 
407 + 4070 + 40700 = 45177 
4107 + 41070 = 45177

Given a Shift Number x, would you please help us find the least integer which could generate x by shifting.

Input

A shift number x. Input ends with x = 0.

Output

the least integer which could generate x by shifting.

Sample Input

136653
45177
0

Sample Output

123
407

Hint

If you are not familiar with "long long", you can consult to FAQ.



Source: Multi-School Training Contest 2010 - BUPT Site #2
Submit   List    Runs   Forum   Statistics


水题,超时一次,原因是自己粗心,把t定义成了int型,存不下while循环一直运行导致超时(粗心的过分啊)。


#include <stdio.h>
using namespace std;
int main(){
	long long n,t;
	while(scanf("%lld",&n) && n){
		t=1;
		while(t<n)
			t=t*10+1;
		while(n%t)
			t/=10;
		printf("%lld\n",n/t);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值