Hdu 1247 Hat's Words (find Hat's word from the given word and output in dictionary order)

Source: Internet
Author: User

1. When using Mp[key] it will go to the key value of the item, if not, he will automatically add a key item, and then the value is assigned to the corresponding initial value (value is an int is assigned to the value of 0,string, the assignment is null). So if you can insert it, you can use find if you are looking for it, so you can save overhead. The time complexity of the lookup is O (logn)


2.

Code:

#include <iostream> #include <string> #include <map>using namespace std;string word[50005];map< String,int> mp;//is implemented with a balanced binary tree, by key from small to large row int main () {    int i=0;    printf ("%d\n", K.max_size ()); Use the container's capacity while    (cin>>word[i++])//Ctrl + Z and enter to end the loop    {        mp[word[ I-1]]=1;//mp[] [] has been overloaded, note is i-1 AH AH!!!!!!    }    Map<string,int>::iterator it;    For (It=mp.begin (); It!=mp.end (); it++)    {        string w=it->first;        for (I=1; I<w.length ()-1; i++)        {            string W1 (w,0,i);//copy [0,i]            string W2 (W,i);//start copying if from the I position of W            ( Mp.find (W1)!=mp.end () &&mp.find (W2)!=mp.end ())            {                cout<<w<<endl;                Break    ;    }}} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu 1247 Hat's Words (find Hat's word from the given word and output in dictionary order)

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.