Ad
Fundamentals
Strings

Added overload for integers and templated overload for list/vector types. Had to add a special rule about whitespaces after a comma, since that is apparently a requirement in the test case, but that could be done probably a bit more nicely.

Code
Diff
  • std::string digest(const std::string param) {
        std::string result;
        for (char letter: param) {
          const std::string whitespace = letter == ',' ? "   " : " ";
          result += std::basic_string(1, letter) + whitespace;
        }
        result.pop_back();
        return result;
    }
    
    std::string digest(const int param) {
      return digest(std::to_string(param));
    }
    
    template<typename T>
    std::stringstream& operator<<(std::stringstream& out, std::initializer_list<T> v) {
      out << "{";
      for (const auto& i : v) {
        out << i << ",";
      }
      std::string temp = out.str();
      temp.pop_back();
      out.str(temp);
      out.seekp(0, std::ios_base::end);
      out << "}";
      std::cout << out.str();
      return out;
    }
    
    template<typename T>
    std::string digest(std::initializer_list<T> param) {
      std::stringstream ss;
      ss << param;
      return digest(ss.str());
    }
    
    
    
    • std::string digest(const std::string param) {
    • std::string result;
    • for (char letter: param) {
    • result += std::basic_string(1, letter) + " ";
    • const std::string whitespace = letter == ',' ? " " : " ";
    • result += std::basic_string(1, letter) + whitespace;
    • }
    • result.pop_back();
    • return result;
    • }
    • }
    • std::string digest(const int param) {
    • return digest(std::to_string(param));
    • }
    • template<typename T>
    • std::stringstream& operator<<(std::stringstream& out, std::initializer_list<T> v) {
    • out << "{";
    • for (const auto& i : v) {
    • out << i << ",";
    • }
    • std::string temp = out.str();
    • temp.pop_back();
    • out.str(temp);
    • out.seekp(0, std::ios_base::end);
    • out << "}";
    • std::cout << out.str();
    • return out;
    • }
    • template<typename T>
    • std::string digest(std::initializer_list<T> param) {
    • std::stringstream ss;
    • ss << param;
    • return digest(ss.str());
    • }