-2

please have a look at my code https://ideone.com/qk7GdO

#include <bits/stdc++.h>
using namespace std;
bool dec(const string &a,const string &b)
{
    if(a.length()!=b.length())
    return a.length()>b.length();
    return a>b;
}
int main() {
    int n,count=0;
    unordered_map<string,vector<string> >hash;
    cin>>n;
    while(n--)
    {
        string str;
        cin>>str;
        int a;
        cin>>a;
        if(hash.find(str)==hash.end())
        count++;
        while(a--)
        {
            string ns;
            cin>>ns;
            hash[str].push_back(ns);
        }
    }
    cout<<count<<endl;
    unordered_map<string,vector<string> >::iterator it;
    for(it=hash.begin();it!=hash.end();it++)
    {
        cout<<it->first;
        vector<string>v;
        for(int i=0;i<(it->second).size();i++)
        {
            string temp=(it->second)[i];
            v.push_back(temp);
        }
        sort(v.begin(),v.end(),dec);
        bool vis[v.size()];
        memset(vis,false,sizeof(vis));
        for(int i=0;i<v.size();i++)
        {
            if(!vis[i])
            {
                for(int j=i+1;j<v.size();j++)
                {
                    if(v[j]==v[i].substr(v[i].length()-v[j].length(),v[j].length()))
                    vis[j]=true;
                }
                cout<<" "<<v[i];
            }
        }
        cout<<endl;
    }


    return 0;
}

i am getting sort() function related compilation errors so it would be really great if someone could help. this is the error i am getting

error: no matching function for call to ‘sort(std::vector<std::__cxx11::basic_string<char> >::iterator, std::vector<std::__cxx11::basic_string<char> >::iterator, <unresolved overloaded function type>)’

Thanks in advance

Quentin
  • 58,778
  • 7
  • 120
  • 175

1 Answers1

1

Your dec is not what you think. (http://en.cppreference.com/w/cpp/io/manip/hex)

That's the danger when you just open the std namespace.

Solutions:

  • remove the using namespace std; (tx @Quentin)
  • rename your dec to something else or
  • fully qualify it: sort(begin(v), end(v), ::dec)
Pete Becker
  • 69,019
  • 6
  • 64
  • 147
xtofl
  • 38,207
  • 10
  • 95
  • 177