ZOJ3449 Doraemon's Number Game III

数根的扩展版,把一个十进制的数,写成按b进制形式的十进制数,一直下去,直到在[0,10)之间。

有a(n)*10^n+a(n-1)*10^(n-1)...+a(0) = a(n)*b^n+a(n-1)*b^(n-1)...+a(0) mod (10 - b)
然后答案就是(n - 10) % (10 - b) + b了。

代码
 
   
#include < iostream >
#include
< math.h >
#include
< deque >
#include
< string >
#include
< vector >
#include
< string .h >
#include
< stdio.h >
#include
< algorithm >
using namespace std;

const int MAX = 100005 ;

char ch[MAX];
int len;

int go( int b)
{
if (len == 1 && ch[ 0 ] <= ' 9 ' ) return ch[ 0 ] - ' 0 ' ;
int res = 0 ;
for ( int i = 0 ; ch[i] != ' \0 ' ; i ++ )
{
res
= res * 10 + ch[i] - ' 0 ' ;
res
%= ( 10 - b);
}
res
= (res - 10 ) % ( 10 - b);
while (res < 0 ) res += ( 10 - b);
return res + b;
}

int main()
{
while (gets(ch))
{
len
= strlen(ch);
for ( int i = 1 ; i <= 9 ; i ++ )
{
if (i == 1 ) printf( " %d " , go(i));
else printf( " %d " , go(i));
}
printf(
" \n " );
}
}

 

转载于:https://www.cnblogs.com/litstrong/archive/2010/12/31/1923301.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值