Problem:
Score : 200 points

Problem Statement

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

Constraints

1 \leq N \leq 10^5

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of positive integers less than or equal to N that have an odd number of digits.

Sample Input 1

11

Sample Output 1

9

Among the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \ldots, 9.

Sample Input 2

136

Sample Output 2

46

In addition to 1, 2, \ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \ldots, 136.

Sample Input 3

100000

Sample Output 3

90909

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int get_int(char *line, int size) {
  if(!fgets(line, size, stdin)) return 0;
  int num;
  sscanf(line, "%d", &num);
  return num;
}

int table[7] = {
  [1] = 9,
  [3] = 999-100+1,
  [5] = 99999-10000+1
};

int pw_table[7] = {
  [1] = 1,
  [3] = 100,
  [5] = 10000
};

int get_digit(int num) {
  int cnt = 0;
  while(num != 0) {
    cnt++;
    num /= 10;
  }
  return cnt;
}

#define BUF_SIZE 10
int main(void) {
  char line[BUF_SIZE];
  int i;
  int num = get_int(line, BUF_SIZE);
  int d = get_digit(num);
  int cnt = 0;
  for(i = 1; i < d; i++) {
    cnt += table[i];
  }
  cnt += (!!table[d]) * (num - pw_table[d] + 1);
  printf("%d\n", cnt);
  return 0;
}