?? pku2408.cpp
字號:
#include <stdio.h>
#include <algorithm>
#include <string>
#include <string.h>
#define L 50
using namespace std;
typedef struct
{
char sw[L], sv[L];
int v;
} Node;
const int size = 30001;
Node word[size];
Node ot[size];
int cnt, ct;
int cp1(const void *a, const void *b)
{
int cv, cw;
Node *aa = (Node *)a;
Node *bb = (Node *)b;
cw = strcmp(aa->sw, bb->sw);
cv = strcmp(aa->sv, bb->sv);
if (cv)
{
return cv;
}
else
{
return cw;
}
}
void Count()
{
int i, j, k;
ot[0].v = 0;
ot[0] = word[0];
for (i = 0, j = 0, k = 0; i < cnt; i++)
{
if (!strcmp(word[i].sv, word[j].sv))
{
ot[k].v++;
}
else
{
j = i;
i--;
k++;
ot[k].v = 0;
ot[k] = word[j];
}
}
ct = k + 1;
}
int cp2(const void *a, const void *b)
{
int cv, cw, cf;
Node *aa = (Node *)a;
Node *bb = (Node *)b;
cw = strcmp(aa->sw, bb->sw);
if (aa->v != bb->v)
{
return bb->v - aa->v;
}
else
{
return cw;
}
}
void OutPut()
{
int i, j;
for (j = 0; j < ct && j < 5; j++)
{
printf("Group of size %d: ", ot[j].v);
for (i = 0; i < cnt; i++)
{
if (!strcmp(word[i].sv, ot[j].sv) && (i == 0 || strcmp(word[i].sw, word[i - 1].sw)))
{
printf("%s ", word[i].sw);
}
}
printf(".\n");
}
}
int main()
{
int i;
cnt = 0;
memset(word, 0, sizeof(word));
while (scanf("%s", word[cnt].sw) != -1)
cnt++;
for (i = 0; i < cnt; i++)
{
strcpy(word[i].sv, word[i].sw);
sort(word[i].sv, word[i].sv + strlen(word[i].sv));
}
qsort(word, cnt, sizeof(word[0]), cp1);
Count();
qsort(ot, ct, sizeof(word[0]), cp2);
OutPut();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -