poj 3286 How many 0's

1106 단어 poj
http://poj.org/problem?id=3286
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<ctime>

#include<queue>

#include<cstring>

#include<set>

#include<cmath>

#include<algorithm>

#define LL long long



using namespace std;



LL Fsum(LL x)

{

    if(x==-1)

    return 0;

    if(x<10)

    return 1;

    LL sum=x/10+1;//   0   

    for(LL i=10;i*10<=x;i=i*10)//       

    {

        if(x/i%10!=0)

        {

            sum+=(i)*(x/i/10);//    0    0       i          x/i/10         

        }else

        {

            sum+=(x/i/10-1)*i+(x%i)+1;//   0                         

        }

    }

    //cout<<sum<<endl;

    return (sum);

}

int main()

{

    //freopen("data.txt","r",stdin);

    LL a,b;

    while(cin>>a>>b)

    {

        if(a==-1&&b==-1)

        break;

        cout<<(Fsum(b)-Fsum(a-1))<<endl;;

    }

    return 0;

}


좋은 웹페이지 즐겨찾기