#include <iostream>

#include <map>
#include <string>

using Map = std::map<std::string, int>; // we don't care about the value here

Map const m = { { "/a/b/c", 0 },
                { "/a/b/d", 0 },
                { "/a/b/c/d", 0 },
                { "/e/f/g", 0 },
                { "/a/x/v", 0 },
                { "/e", 0 },
                { "/a/b/c/d/e", 0 } };

int main() {
	// Note: string comparison orders the string lexicographically
	//       with shorter strings coming first
	auto current = m.begin();
	for (auto it = next(current), end = m.end(); it != end; ++it ) {
		// Note: if current is not a prefix of "it", then it cannot be a prefix
		//       of any key that comes after "it", however of course "it" could
		//       be such a prefix.
		
		// current is not a prefix of "it" if "it" is shorter
		if (it->first.size() <= current->first.size()) { current = it; continue; }
		
		// current is not a prefix of "it"
		if (it->first.substr(0, current->first.size()) != current->first) { current = it; continue; }
		
		// current is a prefix
		std::cout << "'" << current->first << "' is a prefix of '" << it->first << "'\n";
	}
	return 0;
}