Guest User

Untitled

a guest
Dec 17th, 2019
50
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. string unaire;
  14.  
  15. void set(int actuali, int c) {
  16. if(actuali == c) {
  17. unaire += "0";
  18. return;
  19. }
  20. else {
  21. if(c == 0) {
  22. unaire += " 00 0";
  23. return;
  24. }
  25. else if(c == 1) {
  26. unaire += " 0 0";
  27. return;
  28. }
  29. }
  30. }
  31.  
  32. int main()
  33. {
  34. string MESSAGE;
  35. getline(cin, MESSAGE);
  36. string binaire;
  37. int actuali = 4;
  38.  
  39. for(char c : MESSAGE) {
  40. int i = (int) c;
  41. int k = 0;
  42. for(k; i != 0; k++) {
  43. i/=2;
  44. }
  45. i = (int) c;
  46. while(k != 0) {
  47. for(int counter = 0; counter < k; counter ++) {
  48. i/=2;
  49. }
  50. binaire += i % 2;
  51. k--;
  52. i = (int) c;
  53. }
  54. for(char c : binaire) {
  55. int actc = (int) c;
  56. if(actuali != 4) {
  57. set(actuali, actc);
  58. }
  59. else {
  60. if(actc == 0) {
  61. unaire += "00 0";
  62. }
  63. else if(actc == 1){
  64. unaire += "0 0";
  65. }
  66. }
  67. actuali = actc;
  68. }
  69.  
  70. }
  71.  
  72. cout << unaire << endl;
  73.  
  74.  
  75. }
RAW Paste Data