int main()
{
ifstream fin;
fin.open("kriti1.txt");
map<string, set<string>> index_map;
string line, word, page;
int pos;
getline(fin, line);
while (fin)
{
word = "";
page = "";
pos = line.find('{');
for (int i = pos + 1; line[i] != '}' && line[i] != '|'; i++)
{
word += line[i];
}
pos = line.find('{', pos + 1);
for (int i = pos + 1; line[i] != '}'; i++)
{
page += line[i];
}
index_map[word].insert(page);
getline(fin, line);
}
for (const auto& x : index_map)
{
string temp = x.first;
pos = temp.find('!');
while (pos != string::npos)
{
cout << "\t";
temp = temp.substr(pos + 1);
pos = temp.find('!');
}
cout << temp << ": ";
page = "";
if (temp.find("constant") != string::npos)
{
for (const auto& y : x.second)
{
page += y + ", ";
}
page.erase(page.size() - 2, 2);
}
else
{
if (x.second.size() == 1)
{
page = *x.second.begin();
}
else
{
page = *x.second.begin() + '-' + *(--x.second.end());
}
}
cout << page << endl;
}
fin.close();
}