aboutsummaryrefslogtreecommitdiff
path: root/2.3.c
blob: 21b0040f6f0c007115e024561a9d37a3892164ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>

int 
main(void)
{
  char input;
  int num;

  num = 0;
  
  while ((input = getchar()) != EOF) {

    if (input == '0') {
      if ((input = getchar()) == 'x' || input == 'X')
        continue;
      else 
        input = '0';
    }

    if (!((input >= '0' && input <= '9') || (input >= 'a' && input <= 'f') || (input >= 'A' && input <= 'F')))
      continue;
    else if (input >= '0' && input <= '9')
      num = num * 16 + input - '0';
    else if (input >= 'a' && input <= 'f')
      num = num * 16 + 10 + input - 'a';
    else if (input >= 'A' && input <= 'F')
      num = num * 16 + 10 + input - 'A';

  }

  printf("\n%d\n", num);

  return 0;
}