1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/problem/first-letter-capitalization-ii.html
2024-12-20 00:35:26 +08:00

90 lines
3.2 KiB
HTML

<p>Table: <code>user_content</code></p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| content_id | int |
| content_text| varchar |
+-------------+---------+
content_id is the unique key for this table.
Each row contains a unique ID and the corresponding text content.
</pre>
<p>Write a solution to transform the text in the <code>content_text</code> column by applying the following rules:</p>
<ul>
<li>Convert the <strong>first letter</strong> of each word to <strong>uppercase</strong> and the <strong>remaining</strong> letters to <strong>lowercase</strong></li>
<li>Special handling for words containing special characters:
<ul>
<li>For words connected with a hyphen <code>-</code>, <strong>both parts</strong> should be <strong>capitalized</strong> (<strong>e.g.</strong>, top-rated&nbsp;&rarr; Top-Rated)</li>
</ul>
</li>
<li>All other <strong>formatting</strong> and <strong>spacing</strong> should remain <strong>unchanged</strong></li>
</ul>
<p>Return <em>the result table that includes both the original <code>content_text</code> and the modified text following the above rules</em>.</p>
<p>The result format is in the following example.</p>
<p>&nbsp;</p>
<p><strong class="example">Example:</strong></p>
<div class="example-block">
<p><strong>Input:</strong></p>
<p>user_content table:</p>
<pre class="example-io">
+------------+---------------------------------+
| content_id | content_text |
+------------+---------------------------------+
| 1 | hello world of SQL |
| 2 | the QUICK-brown fox |
| 3 | modern-day DATA science |
| 4 | web-based FRONT-end development |
+------------+---------------------------------+
</pre>
<p><strong>Output:</strong></p>
<pre class="example-io">
+------------+---------------------------------+---------------------------------+
| content_id | original_text | converted_text |
+------------+---------------------------------+---------------------------------+
| 1 | hello world of SQL | Hello World Of Sql |
| 2 | the QUICK-brown fox | The Quick-Brown Fox |
| 3 | modern-day DATA science | Modern-Day Data Science |
| 4 | web-based FRONT-end development | Web-Based Front-End Development |
+------------+---------------------------------+---------------------------------+
</pre>
<p><strong>Explanation:</strong></p>
<ul>
<li>For content_id = 1:
<ul>
<li>Each word&#39;s first letter is capitalized: &quot;Hello World Of Sql&quot;</li>
</ul>
</li>
<li>For content_id = 2:
<ul>
<li>Contains the hyphenated word &quot;QUICK-brown&quot; which becomes &quot;Quick-Brown&quot;</li>
<li>Other words follow normal capitalization rules</li>
</ul>
</li>
<li>For content_id = 3:
<ul>
<li>Hyphenated word &quot;modern-day&quot; becomes &quot;Modern-Day&quot;</li>
<li>&quot;DATA&quot; is converted to &quot;Data&quot;</li>
</ul>
</li>
<li>For content_id = 4:
<ul>
<li>Contains two hyphenated words: &quot;web-based&quot; &rarr; &quot;Web-Based&quot;</li>
<li>And &quot;FRONT-end&quot; &rarr; &quot;Front-End&quot;</li>
</ul>
</li>
</ul>
</div>