fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. std::vector<std::string> split( const std::string& code, const std::string& sep )
  6. {
  7. std::vector<std::string> result ;
  8.  
  9. std::string::size_type pos = 0 ;
  10. auto f = code.find(sep) ;
  11. while( f != std::string::npos )
  12. {
  13. result.emplace_back( code.begin()+pos, code.begin()+f ) ;
  14. pos = f + sep.size() ;
  15. f = code.find( sep, pos ) ;
  16. }
  17. result.push_back( code.substr(pos) ) ;
  18.  
  19. return result ;
  20. }
  21.  
  22. int main()
  23. {
  24. const std::string word_seperator = "0000000" ;
  25. const std::string letter_seperator = "000" ;
  26.  
  27. const std::string msg = "111000101010100010000000"
  28. "1110111010111000101011100010100011101011101000111010111" ;
  29. std::cout << "msg: " << msg << '\n' ;
  30. // for each word in msg
  31. for( const std::string& word : split( msg, word_seperator ) )
  32. {
  33. std::cout << " word: " << word << '\n' ;
  34. // for each letter in word
  35. for( const std::string& letter : split( word, letter_seperator ) )
  36. {
  37. std::cout << " letter: " << letter << '\n' ;
  38. // look up letter in map, get the character
  39. }
  40. }
  41. }
  42.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
msg: 1110001010101000100000001110111010111000101011100010100011101011101000111010111
    word: 11100010101010001
        letter: 111
        letter: 1010101
        letter: 1
    word: 1110111010111000101011100010100011101011101000111010111
        letter: 1110111010111
        letter: 1010111
        letter: 101
        letter: 11101011101
        letter: 111010111