Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 为什么纯粹用STL总会让我超时呢，难道我想的太复杂了么。。。那位大牛帮帮我看看呗

Posted by CSUST_14 at 2012-02-15 17:00:01 on Problem 2408
```#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <functional>

using namespace std;

class G
{
private:
int a;
set<string> te;
public:
G(int aa=0,set<string> tee = set<string>()):a(aa),te(tee){}

void insert(string & temp){
a++;te.insert(temp);
}
int geta(){return a;}
set<string> &getset(){return te;}
//bool operator <(G& en)
//{
//		return a>en.a ;
//	}
};

class GG
{
private:
int a;
string b;
set<string>c;
public :
GG(int aa=0,string bb="",set<string> cc = set<string>()):a(aa),b(bb),c(cc){}
bool operator <(const GG& temp){
return a>temp.a||(a==temp.a&&b<temp.b);
}
int getaa() {return a;}
string getst(){return b;}
set<string>& getset(){return c;}
};
int main()
{
map<string,G> gong;
string en;
map<string,G>::iterator it;
while(cin>>en)
{
string temp = en;
sort(en.begin(),en.end ());
it = gong.find (en);
if(it!=gong.end ())
{
it->second .insert (temp);
}
else
{
gong[en].insert (temp);
}
}
typedef vector<GG> yang;
yang yan;
yang::iterator ri;
for(it=gong.begin ();it!=gong.end ();++it)
{
yan.push_back (GG((*it).second .geta (),*((*it).second .getset().begin ()) ,(*it).second .getset()));
}
sort(yan.begin(),yan.end ());

int k=0;
set<string>::iterator iit;
for(ri= yan.begin ();ri!=yan.end ();++ri)
{
k++;
if(k==6) break;
else {cout<<"Group of size "<<(*ri).getaa () <<":";
for(iit=(*ri).getset().begin ();iit!=(*ri).getset().end ();++iit)
{
cout<<" "<<*iit;
}
cout<<" .\n";
}
}
return 0;
}```

Followed by: