#include <iostream>
#include <string>
#include <vector>

void CStringSwitcher()
{
    std::vector<std::string> inputs;
	size_t totalLength = 0;
	
    std::cout << "Enter a sentence on each line. Input a 0 to stop." << std::endl;
	inputs.reserve(16);

	for ( ; /* until break */ ; ) {
		std::cout << ">";
		std::string input;
		getline(std::cin, input);
		if (input == "0")
			break;
		inputs.push_back(input);
		totalLength += input.length() + 1; // for the '\n'
	}

	std::string reversed = "";
	reversed.reserve(totalLength); // eliminate allocations

	for (auto inputsIt = inputs.rbegin(); inputsIt != inputs.rend(); ++inputsIt) {
		const std::string& input = *(inputsIt);

#ifndef REAL_CODE
		// educational, Do-It-Yourself way
		const size_t length = input.length();

		for (size_t i = 0; i < length; ++i) {
			reversed += input[length - 1 - i];
		}
#else
		reversed.append(input.rbegin(), input.rend());
#endif

		reversed += '\n';
	}
	
	std::cout << std::endl << reversed << std::endl;

	// don't pause, set a break point at the end of the function
	// or run without debugging.

    return;
}

int main(int argc, const char* argv[])
{
	CStringSwitcher();

	return 0;
}
