codeforces 204A
给出一个l和r,求取在l和r之间的首尾相同的数的个数。
#include
#include
#include
#include
#define MAX 27
using namespace std;
typedef long long LL;
char l[MAX],r[MAX];
LL dp[MAX],pp[MAX];
void init ( )
{
pp[0] = 1;
for ( int i = 1 ; i < MAX ;i++ )
pp[i] = pp[i-1]*10LL;
}
LL solve ( char s[] )
{
LL ret = 0;
int n = strlen ( s );
if ( n > 1 ) ret += 10;
else ret += s[0]-48+1;
if ( n > 2 ) ret += 9;
for ( int i = 1; i < n-2 ;i++ )
ret += 9LL*pp[i];
for ( int i = 0 ; i < n-1; i++ )
{
int x = s[i]-48;
if ( i == 0 ) x--;
ret += x*pp[n-2-i];
}
if ( n > 1 && s[n-1] >= s[0] ) ret++;
return ret;
}
int main ( )
{
init ( );
while ( ~scanf ( "%s%s" , l , r ) )
{
//cout << solve( r ) << " " << solve ( l ) << endl;
int n = strlen ( l );
printf ( "%I64d\n" , solve ( r ) - solve(l) + ( l[n-1] == l[0]?1LL:0LL) );
}
}