#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>
#include <boost/asio.hpp>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;
using namespace boost::asio;

typedef vector<string>            Strings;
typedef map<string, vector<int> > Dic;

int main()
{
	ip::tcp::iostream src( "www.gnu.org", "http" );

    src << "GET /licenses/gpl.txt HTTP/1.0\r\n"
        << "Host: www.gnu.org\r\n"
        << "\r\n"
        << flush;

    // 読み込み
    Strings lines;
    string  s;
    bool    body = false;
    while(getline(src, s))
    {
        if(body) lines.push_back(s);
        if(s == "\r") body = true;
    }

    // 解析
    regex re("¥¥w+");
    Dic   dic;
    int   lineno = 1;
    for(Strings::const_iterator i = lines.begin(); i != lines.end(); ++i)
    {
        sregex_iterator ri(i->begin(), i->end(), re);
        sregex_iterator end;
        for(; ri != end; ++ri)
        {
            dic[ri->str()].push_back(lineno);
        }
        ++lineno;
    }

    // 書き出し
    for(Dic::const_iterator i = dic.begin(); i != dic.end(); ++i)
    {
        cout << i->first << ":";
        copy(i->second.begin(), i->second.end(), ostream_iterator<int>(cout, ","));
        cout << endl;
    }

    return 0;
}

