用为操作把串压缩为longlong。然后排序。
View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 20005
int n, m;
long long f[maxn];
int id[300];
int ans[maxn];
void input()
{
getchar();
for (int i = 0; i < n; i++)
{
f[i] = 0;
for (int j = 0; j < m; j++)
{
char ch = getchar();
f[i] <<= 2;
f[i] += id[(int)ch];
}
getchar();
}
}
void work()
{
memset(ans, 0, sizeof(ans));
int len = 1;
for (int i = 1; i < n; i++)
if (f[i] != f[i - 1])
{
ans[len]++;
len = 1;
}
else
len++;
ans[len]++;
for (int i = 1; i <= n; i++)
printf("%d\n", ans[i]);
}
int main()
{
//freopen("t.txt", "r", stdin);
id[(int) 'A'] = 0;
id[(int) 'T'] = 1;
id[(int) 'C'] = 2;
id[(int) 'G'] = 3;
while (scanf("%d%d", &n, &m), n | m)
{
input();
sort(f, f + n);
work();
}
return 0;
}