Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your compiler support some c++11 features</p> <pre><code>#include &lt;algorithm&gt; #include &lt;iterator&gt; #include &lt;string&gt; #include &lt;vector&gt; int main() { std::vector&lt;std::vector&lt;std::string&gt; &gt; dictionary(26); //'a' part dictionary[0].push_back("alien"); dictionary[0].push_back("amend"); dictionary[0].push_back("apple"); //....... //'z' part dictionary[25].push_back("zero"); dictionary[25].push_back("zoo"); //sort all of the words after insert for(auto &amp;strs : dictionary){ std::sort(std::begin(strs), std::end(strs)); } //find the specific words of 'a' auto const it = std::equal_range(std::begin(dictionary[0]), std::end(dictionary[0]), "apple"); if(it.first != it.second){ std::cout&lt;&lt;*(it.first)&lt;&lt;std::endl; }else{ std::cout&lt;&lt;"The word do not exist"&lt;&lt;std::endl; } return 0; } </code></pre> <p>if not, then the codes would become a little bit tedious</p> <pre><code>#include &lt;algorithm&gt; #include &lt;string&gt; #include &lt;vector&gt; int main() { std::vector&lt;std::vector&lt;std::string&gt; &gt; dictionary(26); //'a' part dictionary[0].push_back("alien"); dictionary[0].push_back("amend"); dictionary[0].push_back("apple"); //....... //'z' part dictionary[25].push_back("zero"); dictionary[25].push_back("zoo"); //you could use std::for_each if you like, I choose for loop because I //don't like to write so many trivial functor typedef std::vector&lt;std::vector&lt;std::string&gt; &gt;::size_type size_type; size_type const size = dictionary.size(); for(size_type i = 0; i != size; ++i){ std::sort(dictionary[i].begin(), dictionary[i].end()); } //find the specific words of 'a' typedef std::vector&lt;std::string&gt;::const_iterator StrIter; std::pair&lt;StrIter, StrIter&gt; it = std::equal_range(dictionary[0].begin(), dictionary[0].end(), "apple"); if(it.first != it.second){ std::cout&lt;&lt;*(it.first)&lt;&lt;std::endl; }else{ std::cout&lt;&lt;"The word do not exist"&lt;&lt;std::endl; } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload