Guest User

Untitled

a guest
Jan 31st, 2021
10
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. /**
  9. * Auto-generated code below aims at helping you parse
  10. * the standard input according to the problem statement.
  11. **/
  12.  
  13. int main()
  14. {
  15. string msg;
  16. getline(cin, msg);
  17.  
  18. cerr << msg << '\n';
  19.  
  20. string binary;
  21. for(int i = 0; i < msg.length(); i++) {
  22. string bin = "0000000";
  23. if (msg[i] > 63)
  24. bin[0] = '1';
  25. if (msg[i] % 64 > 31)
  26. bin[1] = '1';
  27. if (msg[i] % 64 % 32 > 15)
  28. bin[2] = '1';
  29. if (msg[i] % 64 % 32 % 16 > 7)
  30. bin[3] = '1';
  31. if (msg[i] % 64 % 32 % 16 % 8 > 3)
  32. bin[4] = '1';
  33. if (msg[i] % 64 % 32 % 16 % 8 % 4 > 2)
  34. bin[5] = '1';
  35. if (msg[i] % 64 % 32 % 16 % 8 % 4 % 2 == 1)
  36. bin[6] = '1';
  37. binary += bin;
  38. }
  39.  
  40. cerr << binary << '\n';
  41.  
  42. string unary;
  43.  
  44. char group = binary[0];
  45. int length = 1;
  46. for(int i = 1; i < binary.length(); i++) {
  47. if (binary[i] == group || length == 6)
  48. length += 1;
  49. else {
  50. unary += '0';
  51. if (group == '0')
  52. unary += '0';
  53. unary += ' ';
  54. for(int j = 0; j < length; j++)
  55. unary += '0';
  56. unary += ' ';
  57.  
  58. length = 1;
  59. group = binary[i];
  60. }
  61. }
  62. unary += '0';
  63. if (group == '0')
  64. unary += '0';
  65. unary += ' ';
  66. for(int j = 0; j < length; j++)
  67. unary += '0';
  68. cout << unary << endl;
  69. }
RAW Paste Data