fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class NoNumLiteral {
  7. // no literal !
  8. public:
  9. int numZero;
  10. int numOne;
  11. int numTwo;
  12. int numEight;
  13. int charCodeDot; // '.' = 0x2e
  14. NoNumLiteral () {
  15. numZero = numZero ^ numZero;
  16. numOne = numZero;
  17. numOne++;
  18. numTwo = numOne + numOne;
  19. numEight = numTwo * numTwo * numTwo;
  20. charCodeDot = (numEight * numTwo) * (numTwo + numOne) - numTwo;
  21. }
  22. };
  23.  
  24. class DotString : public string, private NoNumLiteral {
  25. public:
  26. DotString() {}
  27. DotString(const char *inStr) : string(inStr) {}
  28.  
  29. void decode() {
  30. int bitCount;
  31. char ch;
  32. string decodeStr;
  33. string::iterator ich = begin();
  34.  
  35. bitCount = numZero;
  36. ch = numZero;
  37. while (ich < end()) {
  38. ch = (ch << numOne) + (*ich == charCodeDot);
  39. if (++bitCount % numEight == numZero) {
  40. decodeStr.append(numOne, ch);
  41. ch = numZero;
  42. }
  43. ich++;
  44. }
  45. erase();
  46. append(decodeStr);
  47. }
  48.  
  49. void encode() {
  50. // ...
  51. }
  52.  
  53. void print() {
  54. cout << (string&)(*this) << endl;
  55. }
  56. };
  57.  
  58. int main(void) {
  59. // your code goes here
  60. NoNumLiteral num;
  61.  
  62. // dots: bit stream eg. 'A' = 0x41 = 01000001 = "_._____."
  63. DotString dots1("_.__.____..__._._.._..___.._..___.._....__._____");
  64. DotString dots2("_._._..._.._...._...__.__.._..___..__.____.____.");
  65.  
  66. dots1.append(dots2);
  67. dots1.print();
  68. dots1.decode();
  69. dots1.print();
  70.  
  71. return num.numZero;
  72. }
  73.  
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
_.__.____..__._._.._..___.._..___.._....__.______._._..._.._...._...__.__.._..___..__.____.____.
Hello World!