String theme: Map POJ 1002

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.