UVA 156 Ananagrams
来源:互联网 发布:怎么找m2c 厂商 知乎 编辑:程序博客网 时间:2024/05/21 01:46
Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. Such words are called ananagrams, an example is QUIZ.
Obviously such definitions depend on the domain within which we are working; you might think that ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possible domain would be the entire English language, but this could lead to some problems. One could restrict the domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in the same domain) but NOTE is not since it can produce TONE.
Write a program that will read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words are, ipso facto, relative ananagrams since they cannot be ``rearranged'' at all. The dictionary will contain no more than 1000 words.
Input
Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any number of words. Words consist of up to 20 upper and/or lower case letters, and will not be broken across lines. Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words that contain the same letters but of differing case are considered to be anagrams of each other, thus tIeD and EdiT are anagrams. The file will be terminated by a line consisting of a single #.
Output
Output will consist of a series of lines. Each line will consist of a single word that is a relative ananagram in the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will always be at least one relative ananagram.
Sample input
ladder came tape soon leader acme RIDE lone Dreis peat ScAlE orb eye Rides dealer NotE derail LaCeS drIednoel dire Disk mace Rob dries#
Sample output
DiskNotEderaildrIedeyeladdersoon
不能通过字母重新排列得到文本中的另外一个单词的单词
map 映射 vector 不定长
#include<iostream>#include<vector>#include<string>#include<algorithm>#include<map>using namespace std;map<string,int>map1;vector<string>vector1;vector<string>vector2;string biaozhun(const string&a){string d=a;int i;for(i=0;i<d.length();i++){d[i]=tolower(d[i]);}sort(d.begin(),d.end());return d;}int main(){string a;while(cin>>a){if(a[0]=='#')break;vector1.push_back(a);string b=biaozhun(a);if(!map1.count(b))map1[b]=1;elsemap1[b]++;}int l2=vector1.size();int i;for(i=0;i<l2;i++){if(map1[biaozhun(vector1[i])]==1)vector2.push_back(vector1[i]);}sort(vector2.begin(),vector2.end());int l3=vector2.size();for(i=0;i<l3;i++)cout<<vector2[i]<<endl;}
- UVa 156 - Ananagrams
- uva 156 Ananagrams
- UVA 156 - Ananagrams
- UVA 156 - Ananagrams
- UVa 156 - Ananagrams
- uva 156 - Ananagrams
- uva- 156-Ananagrams
- UVa 156 - Ananagrams
- UVA 156 - Ananagrams
- UVa 156 - Ananagrams
- UVa 156 - Ananagrams
- UVA 156 Ananagrams
- uva 156 - Ananagrams
- UVa - 156 - Ananagrams
- uva 156 Ananagrams
- UVa 156 - Ananagrams
- UVA - 156 - Ananagrams
- Uva:156 - Ananagrams
- 2015阿里研发实习 附加题
- 阐明iOS证书和provision文件
- LeetCode题解:Palindrome Number
- empty isset is_null
- asp.net图片分布式存储
- UVA 156 Ananagrams
- 黑马程序员--抽象类与接口
- LeetCode题解:String to Integer (atoi)
- CDMA系统的远近效应问题
- MFC中CSplitter的应用以及在View中添加按钮
- 46家公司程序题答案,均通过上机验证
- POJ 题目1105 S-Trees(二叉树模拟)
- LeetCode题解:Ugly Number
- Spring注解@Component、@Repository、@Service、@Controller区别