#include #include #include #define READ_BUFSIZE ( 128 ) #define READ_DELIMITER ( " " ) //標準入力取得(1行) int GetStdin( char* pszStr, int lMaxLen ) { int lLen = 0; memset( pszStr, 0, lMaxLen ); if( fgets( pszStr, lMaxLen, stdin ) ) { lLen = strlen( pszStr ); if( lLen >= 1 ) { if( pszStr[ lLen - 1 ] == 0x0A ) { pszStr[ lLen - 1 ] = 0; lLen--; } } } return( lLen ); } int main(int argc, char *argv[]) { char szRead[READ_BUFSIZE] = ""; //char* psOutbuf[10000] = { 0 }; int lInput[4] = {0}; GetStdin( szRead, READ_BUFSIZE ); long long int base = 1000000001; //long long int base = 10001; long long int max = strtoull( szRead, 0, 0 ); //long long int max = strtoul( szRead, 0, 0 ); if( max < base ) { printf( "0\n" ); return 0 ; } int i = max / base; char temp[16] = ""; sprintf( temp, "%d", i ); int keta = strlen( temp ); int count = 0; count += (keta-1) *9; char temp2[16] = ""; for( int j = 0; j < keta; j++ ) { temp2[j] = temp[0]; } int k = atoi( temp2 ); memset( temp2+1, 0,sizeof( temp2 )-1 ); count += atoi( temp2 ); if( i < k ) count--; printf( "%d\n", count ); return 0; }