Problem 1410 变位词 from http://acm.fzu.edu.cn/problem.php?pid=1410
2012-09-11 10:27
501 查看
![](http://acm.fzu.edu.cn/image/problem.gif)
Problem 1410 变位词
Accept: 546 Submit: 1584
Time Limit: 1000 mSec Memory Limit : 32768 KB
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Problem Description
Mr. Right有一个奇怪的嗜好,就是看见一个单词就有找它所有的变位词的冲动。一个单词的变位词就是该单词所有字母的一个排列。
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Input
输入数据第一行为一个整数n,1<=n<=10^5,之后n行每行只包含一个单词,不含词组。这些单词构成了Mr. Right的字典。每个单词长度不大于9个字母。接着一行为一个整数m,1<=m<=100,表示Mr. Right将看见的单词数。之后m行每行包含一个单词。(题目中出现的每个单词都只由小写字母组成)
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Output
对应Mr. Right看到的每个单词,输出落在字典里的它的变位词的个数。#include <iostream> #include <algorithm> #include <cstdio> #include <map> #include <cstring> using namespace std; map<string, int> words;//如果用char *,key 为地址 int main(){ //freopen("in.txt", "r", stdin); int n, m; int count; int i,j, times; char a[10]; string str; map<string, int>::iterator it; while(cin>>n){ count = 0; for(i=0;i<n;++i){ scanf(" %s", a); sort(a, a+strlen(a)); str = a;//这里用str存储,然后用str作为key,省去每次的临时转换,大大减少消耗时间 it = words.find(str); if(it == words.end()){ words[str] = 1; }else{ times = it->second + 1; words[str] = times; } } cin>>m; while(m--){ scanf(" %s", a); sort(a, a+strlen(a)); str = a; it = words.find(str); if(it == words.end()){ printf("0\n"); }else{ printf("%d\n", it->second); } } words.clear(); } //fclose(stdin); return 0; }
相关文章推荐
- Problem 1453 Bignum Arithmetic from http://acm.fzu.edu.cn/problem.php?pid=1453
- Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
- Problem 1582 众数问题 from http://acm.fzu.edu.cn/problem.php?pid=1582
- Problem 1046 Tempter of the Bone, from http://acm.fzu.edu.cn/problem.php?pid=1046
- Problem 1057 ab from http://acm.fzu.edu.cn/problem.php?pid=1057
- Problem 1202 信与信封问题 from http://acm.fzu.edu.cn/problem.php?pid=1202
- http://acm.fzu.edu.cn/problem.php?pid=2113 数位DP
- fzu 1402 中国剩余定理 http://acm.fzu.edu.cn/problem.php?pid=1402
- Problem 1607 Greedy division from http://acm.fzu.edu.cn/problem.php?pid=1607
- Problem 1207 半数集问题 from http://acm.fzu.edu.cn/problem.php?pid=1207
- http://acm.fzu.edu.cn/problem.php?pid=1564 C(n,k)和素数P的问题
- hdu 1085 http://acm.hdu.edu.cn/showproblem.php?pid=1085
- 来个图论,http://acm.hdu.edu.cn/showproblem.php?pid=2112
- 亲和串 http://acm.hdu.edu.cn/showproblem.php?pid=2203
- http://acm.hdu.edu.cn/showproblem.php?pid=3584
- 最大报销额 http://acm.hdu.edu.cn/showproblem.php?pid=1864
- http://acm.hdu.edu.cn/showproblem.php?pid=1272。。。
- Number Sequence(http://acm.hdu.edu.cn/showproblem.php?pid=1005)
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=2&cid=963&hide=0
- http://acm.hdu.edu.cn/showproblem.php?pid=1863