One. Map
A map is a mapping from a key (key) to a value (value) that overloads the [] so that it can be considered an advanced version of an array, and some of the common operations are as follows:
Header files: #include <map>
Definition: Map < Type one (key), type two (value) > name key called Map Frist,value is called Map second.
Initialization: Name.clear ();
Two. Topics
Most crossword puzzle fans is used to anagrams--groups of words with the same letters in different orders--for E Xample OPTS, SPOT, STOP, POTS and POST. Some words however do not has this attribute, no matter how to rearrange their letters, you cannot form another word. Such words is called ananagrams, a example is QUIZ.
Obviously such definitions depend on the domain within which we is working; You might think this athene is a ananagram, whereas any chemist would quickly produce ethane. One possible domain would be the entire 中文版 language, but this could leads to some problems. One could restrict the domain to, say, Music, in which case scale becomes arelative Ananagram (laces are not in th e same domain) but NOTE was not since it can produce TONE.
Write a program that would read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words is, ipso facto, relative ananagrams since they cannot is ' rearranged ' at all. The dictionary would contain no more than words.
Input
Input would consist of a series of lines. No line would be more than-characters long, but could contain any number of words. Words consist of up to upper and/or lower case letters, and is not being broken across lines. Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words this contain the same letters but in differing case is considered to being anagrams of each other, thus TIeD and EdiT are anagrams. The file would be terminated to a line consisting of a single #.
Output
Output would consist of a series of lines. Each line would consist of a single word, a relative ananagram in the input dictionary. Words must is output in lexicographic (case-sensitive) order. There always is 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 Driedn Oel dire Disk Mace Rob dries#
Sample Output
Disknotederaildriedeyeladdersoon
Three. Code
#include <iostream> #include <cstdio> #include <map> #include <algorithm> #include <vector > #include <cctype>using namespace std;vector <string> words;map<string,int> counter;int num; String repr (const string& temp) {string r=temp;for (int i=0;i<temp.length (); i++) {r[i]=tolower (temp[i]);} Sort (R.begin (), R.end ()); return r;} int main () {//freopen ("Input.txt", "R", stdin); Counter.clear (); string Temp;num=0;while (Cin>>temp) {if (temp[0]= = ' # ') break;words.push_back (temp);//cout<<temp<< ""; string R;r=repr (temp);counter[r]++;//cout<< r<< "" <<counter[r]<<endl;} Vector <string> ans;for (int i=0;i<=words.size () -1;i++) {if (Counter[repr (Words[i])]==1) ans.push_back (words [i]);} Sort (Ans.begin (), Ans.end ()), for (int i=0;i<ans.size (); i++) {Cout<<ans[i]<<endl;} return 0;}
Three. SummaryThis program uses the case conversion (uppercase converted to lowercase) function tolower (), the function of the header file for Cctype, special attention, it is best to first save the conversion string in the desired conversion to complete the variable, otherwise there will be unknown errors, the use of the best standard.
String repr (const string& temp) {string r=temp;for (int i=0;i<temp.length (); i++) {r[i]=tolower (temp[i]);} Sort (R.begin (), R.end ()); return r;}
UVa 156 (use of STL maps)