题干:
度熊所居住的 D 国,是一个完全尊重人权的国度。以至于这个国家的所有人命名自己的名字都非常奇怪。一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的每一个字符串,也都是这个人的名字。例如,如果一个人名字是 ACM,那么 AMC, CAM, MAC, MCA, 等也都是这个人的名字。在这个国家中,没有两个名字相同的人。
度熊想统计这个国家的人口数量,请帮助度熊设计一个程序,用来统计每一个人在之前被统计过多少次。
Input
这里包括一组测试数据,第一行包含一个正整数NN,接下来的NN 行代表了 NN 个名字。NN 不会超过100,000100,000,他们的名字不会超过40位.
Output
对于每输入的一个人名,输出一个整数,代表这个人之前被统计了多少次。
Sample Input
5 ACM MAC BBA ACM BAB
Sample Output
0 1 0 2 1
解题报告;
想找个办法水掉排序,这样复杂度会很低,但是失败了。。。老老实实用排序。
AC代码:
#include<bits/stdc++.h>using namespace std;
struct Node {int bk[30];bool operator < ( const Node b)const {bk[0]<b.bk[0];}
}tmp1,tmp2;
int main()
{char s[50];int n,len;
// freopen("in.txt","r",stdin);map<string,int> mp;
/* map<Node,int> mp;map<Node,int> ::iterator it;map<int, int> mpp;mpp[1]++;mpp[1]++;cout<<"%%%%"<<mpp[1]<<endl;tmp1.bk[1]=2;tmp2.bk[1]=2;it = mp.begin();//mp[tmp1]++;mp.insert(make_pair(tmp1,0) );cout<<mp[tmp1]<<endl;mp[tmp2]++;cout<<mp[tmp1]<<endl;for(; it!=mp.end(); it++)cout<< it->second <<endl;cout<<"hhhhhhhh"<<endl;
*/cin>>n;while(n--) {Node tmp ;scanf("%s",s);len = strlen(s);sort(s,s+len);printf("%d\n",mp[s]);mp[s]++;/*for(int i = 0 ; i<len; i++) {tmp.bk[s[i]-'a']++;}printf("%d\n",mp[tmp]);mp[tmp]++;*/}return 0 ;
}