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

m=n,m==n==0,这些情况都考虑了,但是还是WA,,应该注意点啥呢?

Posted by zsc08_wangqiang at 2010-08-10 18:52:02 on Problem 3286
牛人们,帮忙看看哈~这是pku2282的代码改过来的。
#include<iostream>
using namespace std;

__int64 an[11], bn[11];

void fun(__int64 sn[],__int64 n)
{
	__int64 i,c,k,s,pown;
	for(k=s=0,pown=1; n>0; k++,n/=10,pown*=10) 
    { 
        c = n % 10;        
        for(i=0; i<10; i++)                
            sn[i] += c * k * (pown/10);                  
        for(i=0; i<c; i++)                
            sn[i] += pown;                
        sn[c] += 1 + s;              
        sn[0] -= pown; 
        s += c * pown; 
    } 
}
int main() 
{ 
	__int64 i, j, a, b;
	while(scanf("%I64d%I64d",&a, &b) && a!=-1 || b!=-1)
	{
		if(a > 0) a--;
		for(i=0;i<10;i++) 
		  an[i] = bn[i] = 0; 
		fun(an, a);
		fun(bn, b);
		//for(i=0;i<9;i++) 
		//	printf("%I64d ", bn[i] - an[i]);
		//printf("%I64d\n",bn[9] - an[9]);
		if(a + 1 == b)
			printf("%I64d\n",(bn[0]-an[0])*2);
		else if((a==0)&&(b==0))
			printf("2\n");
		else if(a == 0)
			printf("%I64d\n",bn[0]-an[0] + 1);
		else printf("%I64d\n",bn[0]-an[0]);
	}
    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