Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>It looks like I'm just going to have to defeat this problem via some very tedious method of character extraction and toppering for each string.</p> </blockquote> <p>Converting the individual strings to upper case and comparing them is not made particularly worse by being restricted from using algorithm, iterator, etc. The comparison logic is about four lines of code. Even though it would be nice not to have to write those four lines having to write a sorting algorithm is far more difficult and tedious. (Well, assuming that the usual C version of <code>toupper</code> is acceptable in the first place.)</p> <p>Below I show a simple <code>strcasecmp()</code> implementation and then put it to use in a complete program which uses restricted libraries. The implementation of <code>strcasecmp()</code> itself doesn't use restricted libraries.</p> <pre><code>#include &lt;string&gt; #include &lt;cctype&gt; #include &lt;iostream&gt; void toupper(std::string &amp;s) { for (char &amp;c : s) c = std::toupper(c); } bool strcasecmp(std::string lhs, std::string rhs) { toupper(lhs); toupper(rhs); return lhs &lt; rhs; } // restricted libraries used below #include &lt;algorithm&gt; #include &lt;iterator&gt; #include &lt;vector&gt; // Example usage: // &gt; ./a.out &lt;&lt;&lt; "C d A b" // A b C d int main() { std::vector&lt;std::string&gt; input; std::string word; while(std::cin &gt;&gt; word) { input.push_back(word); } std::sort(std::begin(input), std::end(input), strcasecmp); std::copy(std::begin(input), std::end(input), std::ostream_iterator&lt;std::string&gt;(std::cout, " ")); std::cout &lt;&lt; '\n'; } </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.
 

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