uva 10994

一开始想法太简单  错了好多遍 

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 10010
#define INF 0x7fffffff
#define inf 10000000
#define ull unsigned long long
#define ll long long
using namespace std;

ll fun(ll n)
{
    if(n == 0) return 0;
    else if (n%10)
        return n%10;
    else
        return  fun(n/10);
}

ll solve(ll a, ll b, ll ans)
{
    if(b - a < 20)
    {
        for(ll i = a; i <= b; ++ i)
            ans += fun(i);
        return ans;
    }
    while(a%10)
    {
        ans += a%10;
        ++ a;
    }
    while(b%10)
    {
        ans += b%10;
        -- b;
    }
    ans += (b-a)/10*45;
    return solve(a/10, b/10, ans);
}

int main()
{
    ll a, b;
    while(scanf("%lld%lld", &a, &b) == 2)
    {
        if(a < 0 && b < 0)
            break;
        printf("%lld\n", solve(a, b, 0));
    }
    return 0;
}




posted @ 2014-01-17 15:51  xlc2845  阅读(136)  评论(0)    收藏  举报