(使用STL自带的排序函数进展排序7.3.6)POJ 2945 Find the Clones拷贝相同次数的文本出现了多少次()

(使用STL自带的排序函数进行排序7.3.6)POJ 2945 Find the Clones拷贝相同次数的文本出现了多少次()
/*
 * POJ_2945.cpp
 *
 *  Created on: 2013年11月1日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 20010;

string strs[maxn];
int ans[maxn];

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF,n||m){
		memset(ans,0,sizeof(ans));

		int i;
		for(i = 0 ; i < n ; ++i){
			cin >>strs[i];
		}

		sort(strs,strs+n);//注意,只是对strs[0]~strs[n-1]的数据进行排序


		int k = 0;//k: 拷贝的次数
		for(i = 1 ; i <= n; ++i){//如过写成i = 0 ; i < n,采用这种方式进行比较会WA
			if(strs[i] == strs[i-1]){//第i个字符串与第i-1个字符串相等
				k++;//拷贝的次数+1
			}else{
				ans[k]++;//ans[k]: 拷贝了k次的字符串有多少份
				k=0;
			}
		}

		for(i = 0 ; i < n ; ++i){
			printf("%d\n",ans[i]);
		}
	}

	return 0;
}