fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const char _ssp_stx = 0x7f;
  7.  
  8. void stx_shrink(vector<char> &a)
  9. {
  10. if (a.size() < 2) return;
  11.  
  12. unsigned i = -1U, q = -1U, n = a.size() - 1;
  13.  
  14. while (++q < n)
  15. if ((a[++i] = a[q]) == _ssp_stx && a[q+1] == _ssp_stx)
  16. ++q;
  17.  
  18. if (q == n)
  19. a[++i] = a[q];
  20.  
  21. a.resize(i+1);
  22. }
  23.  
  24. int main()
  25. {
  26. vector<char> a = { 0x7f, 0x10, 0x7f, 0x7f, 0x10, 0x7f, 0x7f, 0x7f, 0x7f, 0x11, 0x7f, 0x7f };
  27. vector<char> b = { 0x7f, 0x10, 0x10, 0x10, 0x10, 0x7f };
  28. vector<char> c = { 0x7f, 0x10, 0x10, 0x10, 0x7f, 0x7f };
  29. vector<char> d = { 0x7f, 0x7f, 0x10, 0x10, 0x10, 0x7f };
  30. vector<char> e = { 0x7f, 0x7f, 0x10, 0x10, 0x7f, 0x7f };
  31. vector<char> f = { 0x7f, 0x7f };
  32. vector<char> g = { 0x7f, 0x7f, 0x7f };
  33. vector<char> h = { 0x7f, 0x7f, 0x7f, 0x7f };
  34. vector<char> i = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f };
  35. vector<char> j = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f };
  36.  
  37. stx_shrink(a); for (char x : a) cout << hex << (unsigned)x << ' '; cout << endl;
  38. stx_shrink(b); for (char x : b) cout << hex << (unsigned)x << ' '; cout << endl;
  39. stx_shrink(c); for (char x : c) cout << hex << (unsigned)x << ' '; cout << endl;
  40. stx_shrink(d); for (char x : d) cout << hex << (unsigned)x << ' '; cout << endl;
  41. stx_shrink(e); for (char x : e) cout << hex << (unsigned)x << ' '; cout << endl;
  42. stx_shrink(f); for (char x : f) cout << hex << (unsigned)x << ' '; cout << endl;
  43. stx_shrink(g); for (char x : g) cout << hex << (unsigned)x << ' '; cout << endl;
  44. stx_shrink(h); for (char x : h) cout << hex << (unsigned)x << ' '; cout << endl;
  45. stx_shrink(i); for (char x : i) cout << hex << (unsigned)x << ' '; cout << endl;
  46. stx_shrink(j); for (char x : j) cout << hex << (unsigned)x << ' '; cout << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
7f 10 7f 10 7f 7f 11 7f 
7f 10 10 10 10 7f 
7f 10 10 10 7f 
7f 10 10 10 7f 
7f 10 10 7f 
7f 
7f 7f 
7f 7f 
7f 7f 7f 
7f 7f 7f