The first time to use is in the ' School summary ' in the sweep of the problem inside, similar
Map<string,int>str can be used to do string matching such as processing
String Donser;
STR [donser]++ automatically save Donser to map and value plus one if duplicate elements are found not new directly plus one,
Map first parameter is key, default dictionary order ascending key
Map<string,int>::iterator II; The iterator for map
For (Ii=outputer.begin (); Ii!=outputer.end (); ++ii) iterator traversal
{
if (ii->second>1) map the first parameter Ii->first or (*II), the second parameter Ii->second or (*II). Second
{
donser=ii->first;
cout<<donser<< "" <<ii->second<<endl;
}
}
POJ 1002 http://poj.org/problem?id=1002
Do digital processing on the phone number, then match
#include <iostream>#include<cstdio>#include<string>#include<map>using namespacestd;stringAstr;voiddeal () {intlen=astr.size (); for(intI=0; i<len;i++) { if(astr[i]=='-') {astr.erase (I,1); I--; Continue; } if(astr[i]=='A'|| astr[i]=='B'|| astr[i]=='C') {astr.replace (I,1,"2"); } if(astr[i]=='D'|| astr[i]=='E'|| astr[i]=='F') {astr.replace (I,1,"3"); } if(astr[i]=='G'|| astr[i]=='H'|| astr[i]=='I') {astr.replace (I,1,"4"); } if(astr[i]=='J'|| astr[i]=='K'|| astr[i]=='L') {astr.replace (I,1,"5"); } if(astr[i]=='M'|| astr[i]=='N'|| astr[i]=='O') {astr.replace (I,1,"6"); } if(astr[i]=='P'|| astr[i]=='R'|| astr[i]=='S') {astr.replace (I,1,"7"); } if(astr[i]=='T'|| astr[i]=='U'|| astr[i]=='V') {astr.replace (I,1,"8"); } if(astr[i]=='W'|| astr[i]=='X'|| astr[i]=='Y') {astr.replace (I,1,"9"); } } return;}intMain () {intt,lable=0; Map<string,int>Outputer; scanf ("%d",&T); intI=0, j=T; while(j--) {cin>>Astr; Deal (); OUTPUTER[ASTR]++; } Map<string,int>:: Iterator II; for(Ii=outputer.begin (); Ii!=outputer.end (); + +II) {if(ii->second>1) {Astr=ii->First ; Astr.insert (3,"-"); cout<<astr<<" "<<ii->second<<Endl; Lable=1; } } if(!lable) cout<<"No duplicates."; return 0;}
String theme: Map POJ 1002