您的位置:首页 > 其它

2016 百度之星 Problem D (利用STL乱搞)

2016-05-14 23:41 351 查看


Problem D

Accepts: 1785

Submissions: 5157

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/65536 K (Java/Others)

Problem Description

度熊所居住的 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


#include <cstdio>
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <algorithm>
using namespace std;
int main(){
int n;
string s;
int a[45];
map<string,int>M;
while(~scanf("%d",&n)){
cin>>s;
for(int i=0;i<s.length();i++)
a[i] = s[i]-'A';
sort(a,a+s.length());         //灵光一现,想出来了排序826MS水过
for(int i=0;i<s.length();i++)
s[i] = a[i]+'A';

printf("%d\n",M[s]);
M[s]++;
}
return 0;
}
#include <stdio.h>      //大神方法374ms水过
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main(){
map<string,int>M;
int n;
char s[45];
scanf("%d",&n);
while(n--){
scanf("%s",s);
string ss=s;
sort(ss.begin(),ss.end());
printf("%d\n",M[ss]++);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: