Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. Toggle navigation
  2. iRunner 2
  3. OK Solution 204296
  4. Result
  5. Accepted
  6. Score
  7. 100 of 100
  8. Author
  9. Брест 04
  10. Problem
  11. Преобразование последовательности
  12. Input / output
  13. input.txt / output.txt
  14. Contest
  15. Тренировка 3 на задачах минской районки-2017
  16. Submitted
  17. Dec. 16, 2017, 11:08 a.m.
  18. Judged
  19. Dec. 16, 2017, 11:08 a.m.
  20. File
  21. solution.cpp (1.4 KB)
  22. Compiler
  23. C++ GNU C++14 6.2.0 (MinGW) [stack: 64 MB]
  24. Attempts (2)
  25. Source code
  26. Compilation log
  27. Test results
  28. Open Download Select all Style: default
  29. 1
  30. 2
  31. 3
  32. 4
  33. 5
  34. 6
  35. 7
  36. 8
  37. 9
  38. 10
  39. 11
  40. 12
  41. 13
  42. 14
  43. 15
  44. 16
  45. 17
  46. 18
  47. 19
  48. 20
  49. 21
  50. 22
  51. 23
  52. 24
  53. 25
  54. 26
  55. 27
  56. 28
  57. 29
  58. 30
  59. 31
  60. 32
  61. 33
  62. 34
  63. 35
  64. 36
  65. 37
  66. 38
  67. 39
  68. 40
  69. 41
  70. 42
  71. 43
  72. 44
  73. 45
  74. 46
  75. 47
  76. 48
  77. 49
  78. 50
  79. 51
  80. 52
  81. 53
  82. 54
  83. 55
  84. 56
  85. 57
  86. 58
  87. 59
  88. 60
  89. 61
  90. 62
  91. 63
  92. 64
  93. 65
  94. 66
  95. 67
  96. 68
  97. 69
  98. 70
  99. 71
  100. 72
  101. 73
  102. 74
  103. 75
  104. 76
  105. 77
  106. 78
  107. 79
  108. 80
  109. 81
  110. #include <iostream>
  111. #include <vector>
  112. #include <cstdio>
  113. #include <climits>
  114. #include <algorithm>
  115. #include <string>
  116.  
  117. #define int long long
  118. #define For(i,z) for(int i=0;i<z;i++)
  119.  
  120. using namespace std;
  121. const int N = 1e5+2;
  122.  
  123. vector<int> ar(N);
  124.  
  125. int input() {
  126. char c = getchar();
  127. int ans = 0;
  128. bool neg = false;
  129.  
  130. while ((c < '0' || c > '9') && c != '-')
  131. c = getchar();
  132. if (c == '-')
  133. neg = true,
  134. c = getchar();
  135. while (c >= '0' && c <= '9')
  136. ans = ans * 10 + (c - '0'),
  137. c = getchar();
  138.  
  139. if (neg)
  140. return (-ans);
  141. else
  142. return ans;
  143. }
  144.  
  145. int getB(int a) {
  146. bool ar[32] = {false};
  147. int ind = 31;
  148. while (a)
  149. ar[ind] = a % 2,
  150. ind--,
  151. a /= 2;
  152.  
  153. int i;
  154. for (i = ind+1; i < 32; i++)
  155. if (!ar[i]) {
  156. ar[i] = true;
  157. break;
  158. }
  159.  
  160. if (i == 32)
  161. ar[31] = 0;
  162.  
  163. int ans = 0, mn = 1;
  164. for (i = 31; i > ind; i--)
  165. ans = ans + ar[i] * mn,
  166. mn *= 2;
  167.  
  168. return ans;
  169. }
  170.  
  171. int32_t main()
  172. {
  173. freopen("input.txt","r",stdin);
  174. freopen("output.txt","w",stdout);
  175.  
  176. int n;
  177. cin >> n;
  178. ar.resize(n);
  179.  
  180. For (i, n)
  181. ar[i] = getB(input());
  182. For (i, n) {
  183. cout << ar[i];
  184. if (i != n-1)
  185. cout << " ";
  186. }
  187.  
  188.  
  189. return 0;
  190. }
  191. Insight Runner 2 #b0e0cb6
  192. © 2001–2017 DMA department of FAMCS BSU
  193. About Язык / Language Feedback
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement