📄 1469.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 1469 on 2006-02-26 at 17:28:39 */
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
const int MAX = 32768;
const int L_MAX = 32;
class Word {
public:
char con[L_MAX], dic[L_MAX];
bool make();
bool operator <(const Word&) const;
};
bool Word::make() {
if(scanf("%s", con) == EOF) return false;
strcpy(dic, con); sort(dic, dic+strlen(dic));
return true;
}
bool Word::operator <(const Word& w) const {
int r = strcmp(dic, w.dic);
if(r != 0) return r < 0;
else return strcmp(con, w.con) < 0;
}
Word word[MAX];
class Group {
public:
vector<int> ele;
Group() { ele.clear(); }
bool operator <(const Group&) const;
void print() const;
};
bool Group::operator <(const Group& g) const {
if(ele.size() != g.ele.size()) return ele.size() > g.ele.size();
else return strcmp(word[ele[0]].con, word[g.ele[0]].con) < 0;
}
void Group::print() const {
uint i;
printf("Group of size %u: ", ele.size());
for(i = 0; i < ele.size(); i++)
if(i == 0 || strcmp(word[ele[i]].con, word[ele[i-1]].con))
printf("%s ", word[ele[i]].con);
printf(".\n");
}
int main()
{
int i, n, gn = -1;
Group group[MAX];
for(n = 0; word[n].make(); n++) ;
sort(word, word+n);
for(i = 0; i < n; i++) {
if(i == 0 || strcmp(word[i].dic, word[i-1].dic)) ++gn;
group[gn].ele.push_back(i);
}
gn++;
sort(group, group+gn);
for(i = 0; i < gn && i < 5; i++) group[i].print();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -