POJ 2408

题意:对字符串分类,按照每类大小由大到小输出前五个类,没类中相同的字符串只输出一次。

题解:各种STL

View Code
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<queue>
 5 #include<string>
 6 #include<map>
 7 #include<set>
 8 using namespace std;
 9 struct data
10 {
11     vector<string> vec;
12 };
13 map<string,int> MP;
14 set<string> CO;
15 data po[50000];
16 bool comp(data a,data b)
17 {
18     int al=a.vec.size(),bl=b.vec.size();
19     if(al!=bl)
20         return al>bl;
21     else
22         return a.vec[0]<b.vec[0];
23 }
24 int main()
25 {
26     MP.clear();
27     char s[50];
28     int num=0,id;
29     while(gets(s))
30     {
31         char cs[50];
32         strcpy(cs,s);
33         sort(cs,cs+strlen(cs));
34         if(MP.find(cs)==MP.end())
35             id=MP[cs]=++num;
36         else
37             id=MP[cs];
38         po[id].vec.push_back(s);
39     }
40     for(int i=1;i<=num;i++)
41         sort(po[i].vec.begin(),po[i].vec.end());
42     sort(po+1,po+num+1,comp);
43     for(int i=1,k;i<=5&&i<=num;i++)
44     {
45         printf("Group of size %d:",k=po[i].vec.size());
46         for(int j=0;j<k;j++)
47         {
48             if(j>0&&po[i].vec[j]==po[i].vec[j-1])
49                 continue;
50             printf(" %s",po[i].vec[j].c_str());
51         }
52         printf(" .\n");
53     }
54     return 0;
55 }

转载于:https://www.cnblogs.com/tmeteorj/archive/2012/10/20/2731991.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值