fork(3) download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6.  
  7.  
  8. const std::wstring alpha = L"абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
  9.  
  10. typedef std::vector<std::size_t> codeword;
  11.  
  12.  
  13.  
  14. void string_to_codeword(const std::wstring &str, codeword &codes)
  15. {
  16. for (auto ch : str)
  17. {
  18. std::size_t code = alpha.find(ch);
  19. if (code != std::wstring::npos)
  20. codes.push_back(code);
  21. }
  22. }
  23.  
  24. void codeword_to_string(const codeword &codes, std::wstring &str)
  25. {
  26. std::wstring tmp;
  27. for (auto code : codes)
  28. {
  29. std::wcout << L"sym: " << alpha[code] << std::endl;
  30. str += alpha[code];
  31. tmp += alpha[code];
  32. }
  33. std::wcout << tmp << std::endl;
  34. }
  35.  
  36. void encrypt(codeword &src, codeword &dest)
  37. {
  38.  
  39. }
  40.  
  41. int main()
  42. {
  43. std::wstring s = L"абвгде";
  44. codeword codes;
  45.  
  46. string_to_codeword(s, codes);
  47. for (const auto code : codes)
  48. std::cout << code << " ";
  49. std::cout << std::endl;
  50.  
  51.  
  52. std::wstring result;
  53. codeword_to_string(codes, result);
  54. std::wcout << result << std::endl;
  55. }
  56.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 
sym: 0
sym: 1
sym: 2
sym: 3
sym: 4
sym: 5
012345
012345