You have a sequence an, which satisfies:
Now you should find the value of ⌊10an⌋
.
SAMPLE INPUT
20
1314
SAMPLE OUTPUT
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;
}