fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string test= "12345678123456789012";
  7. string counters = test.substr(0, 8);
  8. string idd = test.substr(8,12);
  9.  
  10. unsigned char bitmap = 0xD9;
  11. bool offline = true;
  12.  
  13. if (bitmap & 0x80)
  14. {
  15. if (counters.length() > 6)
  16. {
  17. cout << "Acc1 [" << counters.substr(0,6) << "]" << endl;
  18. counters = counters.substr(6);
  19. }
  20. else if (idd.length() >= 6)
  21. {
  22. cout << "Acc1 [" << idd.substr(0,6) << "]" << endl;
  23. idd = idd.substr(6);
  24. }
  25. else
  26. cout << "Error parsing Acc1" << endl;
  27. }
  28.  
  29. if (bitmap & 0x40)
  30. {
  31. if (counters.length() > 6)
  32. {
  33. cout << "Acc2 [" << counters.substr(0,6) << "]" << endl;
  34. counters = counters.substr(6);
  35. }
  36. else if (idd.length() >= 6)
  37. {
  38. cout << "Acc2 [" << idd.substr(0,6) << "]" << endl;
  39. idd = idd.substr(6);
  40. }
  41. else
  42. cout << "Error parsing Acc2" << endl;
  43. }
  44.  
  45. if (bitmap & 0x20)
  46. {
  47. if (counters.length() > 6)
  48. {
  49. cout << "Acc3 [" << counters.substr(0,6) << "]" << endl;
  50. counters = counters.substr(6);
  51. }
  52. else if (idd.length() >= 6)
  53. {
  54. cout << "Acc3 [" << idd.substr(0,6) << "]" << endl;
  55. idd = idd.substr(6);
  56. }
  57. else
  58. cout << "Error parsing Acc3" << endl;
  59. }
  60.  
  61. if (bitmap & 0x10)
  62. {
  63. if (counters.length() >= 1)
  64. {
  65. cout << "Count1 [" << counters.substr(0,1) << "]" << endl;
  66. counters.erase(0,1);
  67. }
  68. else if (idd.length() >= 1)
  69. {
  70. cout << "Count1 [" << idd.substr(0,1) << "]" << endl;
  71. idd.erase(0,1);
  72. }
  73. else
  74. cout << "Error parsing Count1" << endl;
  75. }
  76.  
  77. if (bitmap & 0x08)
  78. {
  79. if (counters.length() >= 1)
  80. {
  81. cout << "Count2 [" << counters.substr(0,1) << "]" << endl;
  82. counters.erase(0,1);
  83. }
  84. else if (idd.length() >= 1)
  85. {
  86. cout << "Count2 [" << idd.substr(0,1) << "]" << endl;
  87. idd.erase(0,1);
  88. }
  89. else
  90. cout << "Error parsing Count2" << endl;
  91. }
  92.  
  93. if (bitmap & 0x04)
  94. {
  95. if (counters.length() >= 1)
  96. {
  97. cout << "Count3 [" << counters.substr(0,1) << "]" << endl;
  98. counters.erase(0,1);
  99. }
  100. else if (idd.length() >= 1)
  101. {
  102. cout << "Count3 [" << idd.substr(0,1) << "]" << endl;
  103. idd.erase(0,1);
  104. }
  105. else
  106. cout << "Error parsing Count3" << endl;
  107. }
  108.  
  109. if (bitmap & 0x02)
  110. {
  111. if (counters.length() >= 1)
  112. {
  113. cout << "Count4 [" << counters.substr(0,1) << "]" << endl;
  114. counters.erase(0,1);
  115. }
  116. else if (idd.length() >= 1)
  117. {
  118. cout << "Count4 [" << idd.substr(0,1) << "]" << endl;
  119. idd.erase(0,1);
  120. }
  121. else
  122. cout << "Error parsing Count4" << endl;
  123. }
  124.  
  125. if (offline)
  126. {
  127. if (idd.length() >= 3)
  128. {
  129. cout << "Offline [" << idd.substr(0,3) << "]" << endl;
  130. idd.erase(0,3);
  131. }
  132. else
  133. cout << "Error parsing Offline" << endl;
  134. }
  135.  
  136. if (bitmap & 0x01)
  137. {
  138. if (idd.length() >= 3)
  139. {
  140. cout << "Static [" << idd.substr(0,3) << "]" << endl;
  141. idd.erase(0,3);
  142. }
  143. else
  144. cout << "Error parsing Static" << endl;
  145. }
  146. return 0;
  147. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Acc1 [123456]
Acc2 [123456]
Count1 [7]
Count2 [8]
Offline [789]
Static [012]