Submission details
Task:Anagrams
Sender:phid
Submission time:2020-09-26 15:08:55 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:21:39: error: use of 'auto' in lambda parameter declaration only available with -std=c++14 or -std=gnu++14
     sort(v.begin(), v.end(),[] (const auto &a, const auto &b)
                                       ^~~~
input/code.cpp:21:54: error: use of 'auto' in lambda parameter declaration only available with -std=c++14 or -std=gnu++14
     sort(v.begin(), v.end(),[] (const auto &a, const auto &b)
                                                      ^~~~
input/code.cpp: In lambda function:
input/code.cpp:23:18: error: request for member 'first' in 'a', which is of non-class type 'const int'
         return a.first < b.first;
                  ^~~~~
input/code.cpp:23:28: error: request for member 'first' in 'b', which is of non-class type 'const int'
         return a.first < b.first;
                            ^~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:30:23: warning: comparison between signed and unsigned...

Code

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<string, string>> v; // (sorted, orginal)
    string st;
    
    for (int i = 0; i < n; i++) {
        cin >> st;
        string sttmp = st;
        sort(sttmp.begin(), sttmp.end());
        v.push_back(pair<string, string>(sttmp, st));
    }

    sort(v.begin(), v.end(),[] (const auto &a, const auto &b)
    {
        return a.first < b.first;
    }); 
    
    
    vector<int> count(v.size() + 1, 0);
    n = 0;
    
    for (int i = 0; i < v.size() - 1; i++) {
        if (v[i].first == v[i+1].first)
        {
            if (count[i] == 0)
            {
                count[i] = 1;
                n++;
            }
            count[i + 1] = count[i] + 1;
        }
    }
    
    cout << n << endl;

    int i = 0, s = 0;
    while (i < count.size())
    {
        if (count[i] != 0) i++;
        else
        {
            cout << count[i - 1] << endl;
            for (int j = s; j < i; j++) cout << v[j].second << endl;
            while (count[i] == 0 && i < count.size()) i++;
            s = i;
        }
    }
    return 0;
}