#include <iostream>
#include <vector>
#include <map>
#include <regex>
#include <algorithm>
int main() {
std::vector<std::string> Arr = {"1.1", "2.4.5", "1.1.1", "3.4"};
std::map<std::string, std::string> Tmp;
std::regex re(R"((.+?)\.\d)");
std::smatch match;
for (const auto& i : Arr) {
Tmp[i] = "*";
std::string j = i;
while (std::regex_search(j, match, re)) {
j = match.str(1);
Tmp[j] = "*";
}
}
std::vector<std::string> Res;
for (const auto& pair : Tmp) {
Res.push_back(pair.first);
}
std::sort(Res.begin(), Res.end(), [](const std::string& a, const std::string& b) {
return (a.length() == b.length()) ? a < b : a.length() > b.length();
});
for (const auto& item : Res) {
std::cout << item << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8cmVnZXg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CgppbnQgbWFpbigpIHsKICAgIHN0ZDo6dmVjdG9yPHN0ZDo6c3RyaW5nPiBBcnIgPSB7IjEuMSIsICIyLjQuNSIsICIxLjEuMSIsICIzLjQifTsKICAgIHN0ZDo6bWFwPHN0ZDo6c3RyaW5nLCBzdGQ6OnN0cmluZz4gVG1wOwoKICAgIHN0ZDo6cmVnZXggcmUoUiIoKC4rPylcLlxkKSIpOwogICAgc3RkOjpzbWF0Y2ggbWF0Y2g7CgogICAgZm9yIChjb25zdCBhdXRvJiBpIDogQXJyKSB7CiAgICAgICAgVG1wW2ldID0gIioiOwogICAgICAgIHN0ZDo6c3RyaW5nIGogPSBpOwogICAgICAgIHdoaWxlIChzdGQ6OnJlZ2V4X3NlYXJjaChqLCBtYXRjaCwgcmUpKSB7CiAgICAgICAgICAgIGogPSBtYXRjaC5zdHIoMSk7CiAgICAgICAgICAgIFRtcFtqXSA9ICIqIjsKICAgICAgICB9CiAgICB9CgogICAgc3RkOjp2ZWN0b3I8c3RkOjpzdHJpbmc+IFJlczsKICAgIGZvciAoY29uc3QgYXV0byYg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