“玲珑杯”#19 A -- A simple math problem 找规律

DESCRIPTION

You have a sequence an, which satisfies:

Now you should find the value of 10an

.

INPUT
The input includes multiple test cases. The number of test case is less than 1000.Each test case contains only one integer n(1n109)

OUTPUT
For each test case, print a line of one number which means the answer.

SAMPLE INPUT
5
20
1314

SAMPLE OUTPUT
5
21
1317

    抱枕杯签到题,结果纠结了半天才做出来...不小心把后面的 an都当做小于1来处理了...
    这道题题意不用多说,就是图片里的公式,求 10an,因为是向下取整,所以对于公式 an,在 an小于10的时候,一定是一个小于1的数。同理,在 an位于10到100之间时,一定是一个小于2的数,这样的话大部分数可以通过n-位数+1的公式得到。比较特殊的是几个节点,因为差是不断增加的,所以依次为10,99,998....
    下面AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[15];

int init()
{
    int i;
    a[1]=10;
    for(i=2;i<=9;i++)
    {
        a[i]=a[i-1]*10;
    }
    return 0;
}

int main()
{
    int n;
    int t;
    int tim;
    int flag;
    init();
    while(scanf("%d",&n)!=EOF)
    {
        flag=0;
        if(n==1)
        {
            cout<<1<<endl;
            continue;
        }
        tim=0;
        t=n;
        while(t>10)
        {
            t=t/10;
            tim++;
        }
        tim++;
        if(a[tim]-n<tim-1)
            flag=1;
        if(flag==0)
            cout<<n+tim-1<<endl;
        else
            cout<<n+tim<<endl;
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值