您的位置:首页 > 其它

【51Nod】1095 - Anigram单词(STL - map)

2017-02-28 17:08 447 查看
题目链接:点击打开题目



题解:直接用map记录,然后排序再记录,相减就求出来了。

代码如下:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a))
#define PI acos(-1.0)
#define LL long long
int main()
{
int n;
map<string,int> a;      //字符串出现次数
map<string,int> b;      //排序后字符串出现次数
string str;
scanf ("%d",&n);
while (n--)
{
cin >> str;
a[str]++;
sort(str.begin(),str.end());
b[str]++;
}
scanf ("%d",&n);
while (n--)
{
cin >> str;
int x = a[str];
sort(str.begin(),str.end());
int y = b[str];
printf ("%d\n",y-x);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  stl