fork download
  1. #include <array>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. std::string zip_to_postnet(const std::string& zip)
  6. {
  7. std::array<std::string,10> lookup{"11000", "00011", "00101", "00110",
  8. "01001", "01010", "01100", "10001",
  9. "10010", "10100"};
  10.  
  11. std::string result = "1";
  12.  
  13. for (unsigned int i = 0; i < 5; ++i)
  14. {
  15. int digit = zip[i] - '0';
  16. result += lookup[digit];
  17. }
  18.  
  19. return result + "1";
  20. }
  21.  
  22. int main()
  23. {
  24. std::cout << zip_to_postnet("24060") << std::endl;
  25. std::cout << zip_to_postnet("92064") << std::endl;
  26. std::cout << zip_to_postnet("11518") << std::endl;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
100101010011100001100110001
110100001011100001100010011
100011000110101000011100101