[51NOD1095] Anigram单词(map)

题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1095

字典的单词在map中排序和不排序各存1次,查的时候相减。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int maxn = 10100;
 5 int n, q;
 6 char tmp[12];
 7 map<string, int> d1;
 8 map<string, int> d2;
 9 
10 int main() {
11   // freopen("in", "r", stdin);
12   while(~scanf("%d",&n)) {
13     d1.clear(); d2.clear();
14     for(int i = 0; i < n; i++) {
15       scanf("%s", tmp);
16       d1[tmp]++;
17       sort(tmp, tmp+strlen(tmp));
18       d2[tmp]++;
19     }
20     scanf("%d",&q);
21     while(q--) {
22       scanf("%s", tmp);
23       int a = d1[tmp];
24       sort(tmp, tmp+strlen(tmp));
25       int b = d2[tmp];
26       printf("%d
", b-a);
27     }
28   }
29   return 0;
30 }
原文地址:https://www.cnblogs.com/kirai/p/6000568.html