Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
分治法#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator