Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. //#include <iostream>
  2. //#include <vector>
  3. //#include <map>
  4. //#include <cinttypes>
  5.  
  6.  
  7. //typedef enum {
  8. // PlusZero = 0x00,
  9. // MinusZero = 0x01,
  10. // PlusInf = 0xF0,
  11. // MinusInf = 0xF1,
  12. // PlusRegular = 0x10,
  13. // MinusRegular = 0x11,
  14. // PlusDenormal = 0x20,
  15. // MinusDenormal = 0x21,
  16. // SignalingNaN = 0x30,
  17. // QuietNaN = 0x31
  18. //} float_class_t;
  19. //
  20. //typedef union {
  21. // double f;
  22. // struct {
  23. // uint64_t mantissa : 52;
  24. // uint64_t exponent : 11;
  25. // uint64_t sign : 1;
  26. // } parts;
  27. //} double_cast;
  28. //
  29. //extern float_class_t
  30. //classify(double *value_ptr) {
  31. // double_cast cast_ = {.f = *value_ptr};
  32. // uint64_t sign = cast_.parts.sign;
  33. // uint64_t exponent = cast_.parts.exponent;
  34. // uint64_t mantissa = cast_.parts.mantissa;
  35. //
  36. // std::cout << sign << ' ' << exponent << ' ' << mantissa << '\n';
  37. //
  38. // if (sign == 0 && exponent == 0 && mantissa == 0) {
  39. // return PlusZero;
  40. // }
  41. //
  42. // if (sign == 1 && exponent == 0 && mantissa == 0) {
  43. // return MinusZero;
  44. // }
  45. //
  46. // if (sign == 0 && exponent == 0x7ff && mantissa == 0) {
  47. // return PlusInf;
  48. // }
  49. //
  50. // if (sign == 1 && exponent == 0x7ff && mantissa == 0) {
  51. // return MinusInf;
  52. // }
  53. //
  54. // if (sign == 0 && exponent == 0x7ff && mantissa == 0x1) {
  55. // return SignalingNaN;
  56. // }
  57. //
  58. // if (sign == 0 && exponent == 0x7ff && mantissa == 0x2) {
  59. // return QuietNaN;
  60. // }
  61. //}
  62.  
  63. #include <stdio.h>
  64. #include <stdint.h>
  65. #include <ctype.h>
  66.  
  67.  
  68. int char_to_int(char letter) {
  69. if (letter >= '0' && letter <= '9') {
  70. return (int) letter - 48;
  71. }
  72.  
  73. if (letter >= 'A' && letter <= 'Z') {
  74. return (int) letter - 55;
  75. }
  76.  
  77. if (letter >= 'a' && letter <= 'z') {
  78. return (int) letter - 61;
  79. }
  80.  
  81. return -1;
  82. }
  83.  
  84.  
  85. char int_to_char(int index) {
  86. if (index >= 0 && index <= 9) {
  87. return (char) (48 + index);
  88. }
  89.  
  90. index -= 10;
  91.  
  92. if (index >= 0 && index < 26) {
  93. return (char) (65 + index);
  94. }
  95.  
  96. index -= 26;
  97. return (char) (97 + index);
  98. }
  99.  
  100. void print_answer(uint64_t arr) {
  101. for (int i = 0; i < 62; ++i) {
  102. if (arr & ((uint64_t) 1 << i)) {
  103. fputc(int_to_char(i), stdout);
  104. }
  105. }
  106. fputc('\n', stdout);
  107. }
  108.  
  109.  
  110. int main() {
  111. uint64_t initial = 0;
  112. uint64_t current = 0;
  113.  
  114. for (;;) {
  115. int c = fgetc(stdin);
  116. if (c == EOF) {
  117. break;
  118. }
  119.  
  120. if ((char) c == '&') {
  121. initial &= current;
  122. current = 0;
  123. }
  124.  
  125. if ((char) c == '|') {
  126. initial |= current;
  127. current = 0;
  128. }
  129.  
  130. if ((char) c == '^') {
  131. initial ^= current;
  132. current = 0;
  133. }
  134.  
  135. if ((char) c == '~') {
  136. uint64_t universe = (((uint64_t) 1 << 62) - 1);
  137. initial = universe ^ initial;
  138. }
  139.  
  140. if (isalpha(c) || isdigit(c)) {
  141. current |= ((uint64_t) 1 << char_to_int((char) c));
  142. }
  143. }
  144.  
  145. print_answer(initial);
  146.  
  147. return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement