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 lyyshp at 2016-03-22 18:35:43 on Problem 3286
#include <stdio.h>
unsigned int count0( unsigned int n )
{
	unsigned int s = 0, t, x, y;
	t = n, x = 1;
	while( 1 ){
		y = t % 10;
		t /= 10;
		if( t ) s += (t - 1) * x + ( y ? x : (n % x + 1) );
		else return s;
		x *= 10;
	}
}
unsigned int trans( char *str )
{
	unsigned int s = 0, i;
	for( i = 0; str[i]; i ++ ) s = s * 10 + str[i] - 48;
	return s;
}
int main()
{
	unsigned int a, b; 
	char s1[11], s2[11];
	while( scanf( "%s%s", s1, s2 ) && s1[0] != '-' ){
		a = trans( s1 ), b = trans( s2 );
		if( a ) printf( "%u\n", count0( b ) - count0( a - 1 ) );
		else printf( "%u\n", count0( b ) + 1 );		
	}
	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