Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     uint64_t ans = 0, x = 0;
  8.     std::string s;
  9.     getline(std::cin, s);
  10.     for (uint8_t byte : s) {
  11.         ans += (static_cast<uint64_t>(byte - (byte & (1 << 7)))) << x;
  12.         x += 7;
  13.         if (byte & (1 << 7) == 0)
  14.             break;
  15.     }
  16.     cout << ans;
  17. }
  18.  
  19.  
  20.  
  21.  
  22.  
  23. #include <iostream>
  24. #include <string>
  25. #include <algorithm>
  26.  
  27. using namespace std;
  28.  
  29. int main() {
  30.     int ans = 0, x = 0;
  31.     std::string s;
  32.     getline(std::cin, s);
  33.     for (uint8_t byte : s) {
  34.         if (x != 0) {
  35.             x--;
  36.         } else {
  37.             ans++;
  38.             for (int i = 7; i >= 0; --i) {
  39.                 if ((byte & (1 << i)) != 0) {
  40.                     x++;
  41.                 } else {
  42.                     break;
  43.                 }
  44.             }
  45.             x = max(0, x - 1);
  46.         }
  47.     }
  48.     cout << ans;
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55. #include <iostream>
  56. #include <string>
  57. #include <algorithm>
  58.  
  59. using namespace std;
  60.  
  61. int main() {
  62.     int ans = 0, x = 7, notFirst = 0;
  63.     std::string s;
  64.     getline(std::cin, s);
  65.     for (uint8_t byte : s) {
  66.         while (byte & (1 << x))
  67.             x--;
  68.         if (x != 6) {
  69.             if (notFirst)
  70.                 cout << ans << ' ';
  71.             ans = 0;
  72.         }
  73.         while (x > 0) {
  74.             x--;
  75.             ans <<= 1;
  76.             if (byte & (1 << x))
  77.                 ans++;
  78.         }
  79.         x = 7;
  80.         notFirst = 1;
  81.     }
  82.     cout << ans;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. #include <iostream>
  90.  
  91. using namespace std;
  92.  
  93. int main() {
  94.     int code;
  95.     while (cin >> code) {
  96.         if (code < (1 << 7)) {
  97.             cout.write(reinterpret_cast<char*>(&code), sizeof(uint8_t));
  98.         } else if (code < (1 << 11)) {
  99.             char x = (1 << 7) + (1 << 6);
  100.             for (int i = 4; i >= 0; --i) {
  101.                 if (code & (1 << (6 + i)))
  102.                     x += (1 << i);
  103.             }
  104.             cout.write(&x, sizeof(char));
  105.             x = (1 << 7);
  106.             for (int i = 5; i >= 0; --i) {
  107.                 if (code & (1 << (i)))
  108.                     x += (1 << i);
  109.             }
  110.             cout.write(&x, sizeof(char));
  111.         } else if (code < (1 << 16)) {
  112.             char x = (1 << 7) + (1 << 6) + (1 << 5);
  113.             for (int i = 3; i >= 0; --i) {
  114.                 if (code & (1 << (12 + i)))
  115.                     x += (1 << i);
  116.             }
  117.             cout.write(&x, sizeof(uint8_t));
  118.             x = (1 << 7);
  119.             for (int i = 5; i >= 0; --i) {
  120.                 if (code & (1 << (6 + i)))
  121.                     x += (1 << i);
  122.             }
  123.             cout.write(&x, sizeof(uint8_t));
  124.             x = (1 << 7);
  125.             for (int i = 5; i >= 0; --i) {
  126.                 if (code & (1 << (i)))
  127.                     x += (1 << i);
  128.             }
  129.             cout.write(&x, sizeof(uint8_t));
  130.         } else if (code < (1 << 21)) {
  131.             char x = (1 << 7) + (1 << 6) + (1 << 5) + (1 << 4);
  132.             for (int i = 2; i >= 0; --i) {
  133.                 if (code & (1 << (18 + i)))
  134.                     x += (1 << i);
  135.             }
  136.             cout.write(&x, sizeof(uint8_t));
  137.             x = (1 << 7);
  138.             for (int i = 5; i >= 0; --i) {
  139.                 if (code & (1 << (12 + i)))
  140.                     x += (1 << i);
  141.             }
  142.             cout.write(&x, sizeof(uint8_t));
  143.             x = (1 << 7);
  144.             for (int i = 5; i >= 0; --i) {
  145.                 if (code & (1 << (6 + i)))
  146.                     x += (1 << i);
  147.             }
  148.             cout.write(&x, sizeof(uint8_t));
  149.             x = (1 << 7);
  150.             for (int i = 5; i >= 0; --i) {
  151.                 if (code & (1 << (i)))
  152.                     x += (1 << i);
  153.             }
  154.             cout.write(&x, sizeof(uint8_t));
  155.         }
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement