#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int M = 30005;
struct node {
char org[50];
char ord[500];
}word[M];
struct Node {
int num;
int fist;
int start;
}group[M];
int k;
int cmp(node p1, node p2) {
if(strcmp(p1.ord, p2.ord) != 0)
return strcmp(p1.ord, p2.ord) < 0;
return strcmp(p1.org, p2.org) <= 0;
}
int cmp1(Node p1, Node p2) {
if(p1.num != p2.num)
return p1.num > p2.num;
return strcmp(word[p1.fist].org, word[p2.fist].org) <= 0;
}
int main()
{
k = 0;
while(scanf("%s", word[k].org) != EOF) {
strcpy(word[k].ord, word[k].org);
int len = strlen(word[k].ord);
sort(word[k].ord, word[k].ord + len);
k++;
}
sort(word, word + k,cmp);
int a = 1;
group[0].fist = 0;
group[0].start = 0;
group[0].num = 1;
for(int i = 1; i < k; i++) {
if(strcmp(word[i].ord, word[group[a-1].start].ord) == 0){
group[a-1].num++;
}
else {
group[a].fist = i;
group[a].start = i;
group[a].num = 1;
a++;
}
}
sort(group, group + a, cmp1);
for(int i = 0; i < 5; i++) {
printf("Group of size %d: ",group[i].num);
int p=group[i].start;
printf("%s ", word[p].org);
for(int j = 1; j < group[i].num; j++) {
if(strcmp(word[p+j].org,word[p+j-1].org)!=0) {
printf("%s ", word[p+j].org);
}
}
printf(".\n");
}
return 0;
}
poj 2408 字符串模拟题(值得回顾)。
最新推荐文章于 2023-09-25 20:49:00 发布