123456789101112131415161718192021222324252627282930313233343536 |
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- int main() {
- char str[100];
- fgets(str, 100, stdin);
- // Remove newline character
- str[strcspn(str, "\n")] = '\0';
- int is_negative = 0;
- int hex_found = 0;
- int i;
- unsigned long long decimal = 0;
- for (i = 0; str[i] != '#'; i++) {
- if (str[i] == '-') {
- is_negative = 1;
- } else if (isxdigit(str[i])) {
- hex_found = 1;
- char hex_char = toupper(str[i]);
- int hex_value = isdigit(hex_char) ? hex_char - '0' : hex_char - 'A' + 10;
- decimal = decimal * 16 + hex_value;
- }
- }
- if (is_negative) {
- decimal = -decimal;
- }
- printf("%lld\n", decimal);
- return 0;
- }
|