Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴代码

Posted by sdjzkx at 2011-08-10 10:32:30 on Problem 2282
In Reply To:这样找不好么?但是超时,求解 Posted by:sdjzuLH at 2011-08-10 09:51:50
#include<iostream>
#include<memory.h>
#include<cmath>
using namespace std;
int res[10];
int tmp[10];
int c=1;
void search(int a)
{
    int x=a/10;
    int y=a%10;
    int t=x;
    for(int i=0;i<=y;i++)
    res[i]+=c;
    while(t)
    {
        res[t%10]+=c*(y+1);
        t/=10;
    }
    for(int i=0;i<10;i++)
    res[i]+=x*c;
    res[0]-=c;
    c=c*10;
    if(x!=0)
    search(x-1);
}
int main()
{
    int a,b;
    while(cin>>a>>b,a||b)
    {
        c=1;
        memset(res,0,sizeof(res));
        if(a>b)
        swap(a,b);
        search(a-1);
        for(int i=0;i<10;i++)
        {
            tmp[i]=res[i];
            res[i]=0;
        }
        c=1;
        search(b);
        for(int i=0;i<10;i++)
        cout<<res[i]-tmp[i]<<" ";
        cout<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator