mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-01 01:32:32 +08:00
Documentation for f1eddf4d65
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.13.2"/>
|
||||
<meta name="generator" content="Doxygen 1.14.0"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>TheAlgorithms/C++: dynamic_programming/abbreviation.cpp File Reference</title>
|
||||
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
||||
@@ -19,7 +19,6 @@
|
||||
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../navtreedata.js"></script>
|
||||
<script type="text/javascript" src="../../navtree.js"></script>
|
||||
<script type="text/javascript" src="../../resize.js"></script>
|
||||
<script type="text/javascript" src="../../cookie.js"></script>
|
||||
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
||||
@@ -60,26 +59,20 @@ window.MathJax = {
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.13.2 -->
|
||||
<!-- Generated by Doxygen 1.14.0 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
||||
/* @license-end */
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(function() { codefold.init(1); });
|
||||
/* @license-end */
|
||||
$(function() { codefold.init(); });
|
||||
</script>
|
||||
<script type="text/javascript" src="../../menudata.js"></script>
|
||||
<script type="text/javascript" src="../../menu.js"></script>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(function() {
|
||||
initMenu('../../',true,false,'search.php','Search',true);
|
||||
$(function() { init_search(); });
|
||||
});
|
||||
/* @license-end */
|
||||
</script>
|
||||
<div id="main-nav"></div>
|
||||
</div><!-- top -->
|
||||
@@ -94,10 +87,9 @@ $(function() {
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(function(){initNavTree('d7/d73/abbreviation_8cpp.html','../../'); initResizable(true); });
|
||||
/* @license-end */
|
||||
$(function(){initNavTree('d7/d73/abbreviation_8cpp.html','../../',''); });
|
||||
</script>
|
||||
<div id="container">
|
||||
<div id="doc-content">
|
||||
<!-- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
@@ -121,9 +113,6 @@ $(function(){initNavTree('d7/d73/abbreviation_8cpp.html','../../'); initResizabl
|
||||
</div>
|
||||
|
||||
<div class="header">
|
||||
<div class="summary">
|
||||
<a href="#namespaces">Namespaces</a> |
|
||||
<a href="#func-members">Functions</a> </div>
|
||||
<div class="headertitle"><div class="title">abbreviation.cpp File Reference</div></div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
@@ -138,52 +127,46 @@ $(function(){initNavTree('d7/d73/abbreviation_8cpp.html','../../'); initResizabl
|
||||
</div><div class="textblock"><div class="dynheader">
|
||||
Include dependency graph for abbreviation.cpp:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../da/d76/abbreviation_8cpp__incl.svg" width="415" height="126"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
<div class="center"><iframe scrolling="no" loading="lazy" frameborder="0" src="../../da/d76/abbreviation_8cpp__incl.svg" width="415" height="126"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
</div>
|
||||
<p><a href="../../d7/d73/abbreviation_8cpp_source.html">Go to the source code of this file.</a></p>
|
||||
<table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
|
||||
<tr class="heading"><td colspan="2"><h2 id="header-namespaces" class="groupheader"><a id="namespaces" name="namespaces"></a>
|
||||
Namespaces</h2></td></tr>
|
||||
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">namespace  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d24/namespacedynamic__programming.html">dynamic_programming</a></td></tr>
|
||||
<tr class="memitem:dynamic_5Fprogramming" id="r_dynamic_5Fprogramming"><td class="memItemLeft" align="right" valign="top">namespace  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d24/namespacedynamic__programming.html">dynamic_programming</a></td></tr>
|
||||
<tr class="memdesc:dd/d24/namespacedynamic__programming"><td class="mdescLeft"> </td><td class="mdescRight">Dynamic Programming algorithms. <br /></td></tr>
|
||||
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">namespace  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/df8/namespaceabbreviation.html">abbreviation</a></td></tr>
|
||||
<tr class="memitem:abbreviation" id="r_abbreviation"><td class="memItemLeft" align="right" valign="top">namespace  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/df8/namespaceabbreviation.html">abbreviation</a></td></tr>
|
||||
<tr class="memdesc:d0/df8/namespaceabbreviation"><td class="mdescLeft"> </td><td class="mdescRight">Functions for <a href="https://www.hackerrank.com/challenges/abbr/problem" target="_blank">Abbreviation</a> implementation. <br /></td></tr>
|
||||
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table><table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
||||
<tr class="heading"><td colspan="2"><h2 id="header-func-members" class="groupheader"><a id="func-members" name="func-members"></a>
|
||||
Functions</h2></td></tr>
|
||||
<tr class="memitem:add60b8858720bf217df22d992d0fefaa" id="r_add60b8858720bf217df22d992d0fefaa"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#add60b8858720bf217df22d992d0fefaa">dynamic_programming::abbreviation::abbreviation_recursion</a> (std::vector< std::vector< bool > > *memo, std::vector< std::vector< bool > > *visited, const std::string &str, const std::string &result, uint32_t str_idx=0, uint32_t result_idx=0)</td></tr>
|
||||
<tr class="memdesc:add60b8858720bf217df22d992d0fefaa"><td class="mdescLeft"> </td><td class="mdescRight">Recursive Dynamic Programming function. <br /></td></tr>
|
||||
<tr class="separator:add60b8858720bf217df22d992d0fefaa"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:af53b2f647bee9c5b75ef8dd9ef685dc8" id="r_af53b2f647bee9c5b75ef8dd9ef685dc8"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="#af53b2f647bee9c5b75ef8dd9ef685dc8">dynamic_programming::abbreviation::abbreviation</a> (const std::string &str, const std::string &result)</td></tr>
|
||||
<tr class="memdesc:af53b2f647bee9c5b75ef8dd9ef685dc8"><td class="mdescLeft"> </td><td class="mdescRight">Iterative Dynamic Programming function. <br /></td></tr>
|
||||
<tr class="separator:af53b2f647bee9c5b75ef8dd9ef685dc8"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d" id="r_aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
||||
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Self test-implementations. <br /></td></tr>
|
||||
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4" id="r_ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
||||
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <br /></td></tr>
|
||||
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<a name="details" id="details"></a><h2 id="header-details" class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Implementation of <a href="https://www.hackerrank.com/challenges/abbr/problem" target="_blank">Abbrievation</a> </p>
|
||||
<p>Given two strings, <code>a</code> and <code>b</code>, determine if it's possible to make <code>a</code> equal to <code>b</code> You can perform the following operations on the string <code>a</code>:</p><ol type="1">
|
||||
<li>Capitalize zero or more of <code>a</code>'s lowercase letters.</li>
|
||||
<li>Delete all of the remaining lowercase letters in <code>a</code>.</li>
|
||||
<p>Given two strings, <span class="tt">a</span> and <span class="tt">b</span>, determine if it's possible to make <span class="tt">a</span> equal to <span class="tt">b</span> You can perform the following operations on the string <span class="tt">a</span>:</p><ol type="1">
|
||||
<li>Capitalize zero or more of <span class="tt">a</span>'s lowercase letters.</li>
|
||||
<li>Delete all of the remaining lowercase letters in <span class="tt">a</span>.</li>
|
||||
</ol>
|
||||
<h3><a class="anchor" id="autotoc_md70"></a>
|
||||
<h3 class="doxsection"><a class="anchor" id="autotoc_md70"></a>
|
||||
Algorithm</h3>
|
||||
<p>The idea is in the problem statement itself: iterate through characters of string <code>a</code> and <code>b</code> (for character indexes <code>i</code> and <code>j</code> respectively):</p><ol type="1">
|
||||
<li>If <code>a[i]</code> and <code>b[j]</code> are equal, then move to next position</li>
|
||||
<li>If <code>a[i]</code> is lowercase of <code>b[j]</code>, then explore two possibilities: a. Capitalize <code>a[i]</code> or b. Skip <code>a[i]</code></li>
|
||||
<li>If the <code>a[i]</code> is not uppercase, just discard that character, else return <code>false</code></li>
|
||||
<p>The idea is in the problem statement itself: iterate through characters of string <span class="tt">a</span> and <span class="tt">b</span> (for character indexes <span class="tt">i</span> and <span class="tt">j</span> respectively):</p><ol type="1">
|
||||
<li>If <span class="tt">a[i]</span> and <span class="tt">b[j]</span> are equal, then move to next position</li>
|
||||
<li>If <span class="tt">a[i]</span> is lowercase of <span class="tt">b[j]</span>, then explore two possibilities: a. Capitalize <span class="tt">a[i]</span> or b. Skip <span class="tt">a[i]</span></li>
|
||||
<li>If the <span class="tt">a[i]</span> is not uppercase, just discard that character, else return <span class="tt">false</span></li>
|
||||
</ol>
|
||||
<p>Time Complexity: (O(|a|*|b|)) where <code>|a|</code> => length of string <code>a</code> </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/AshishYUO" target="_blank">Ashish Daulatabad</a> </dd></dl>
|
||||
<p>Time Complexity: (O(|a|*|b|)) where <span class="tt">|a|</span> => length of string <span class="tt">a</span> </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/AshishYUO" target="_blank">Ashish Daulatabad</a> </dd></dl>
|
||||
|
||||
<p class="definition">Definition in file <a class="el" href="../../d7/d73/abbreviation_8cpp_source.html">abbreviation.cpp</a>.</p>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
</div><a name="doc-func-members" id="doc-func-members"></a><h2 id="header-doc-func-members" class="groupheader">Function Documentation</h2>
|
||||
<a id="af53b2f647bee9c5b75ef8dd9ef685dc8" name="af53b2f647bee9c5b75ef8dd9ef685dc8"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#af53b2f647bee9c5b75ef8dd9ef685dc8">◆ </a></span>abbreviation()</h2>
|
||||
|
||||
@@ -204,16 +187,16 @@ Algorithm</h3>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Iterative Dynamic Programming function. </p>
|
||||
<p>Returns whether <code>s</code> can be converted to <code>t</code> with following rules: a. Capitalize zero or more of s's lowercase letters from string <code>s</code> b. remove all other lowercase letters from string <code>s</code> Note: The transition states for iterative is similar to recursive as well </p><dl class="params"><dt>Parameters</dt><dd>
|
||||
<p>Returns whether <span class="tt">s</span> can be converted to <span class="tt">t</span> with following rules: a. Capitalize zero or more of s's lowercase letters from string <span class="tt">s</span> b. remove all other lowercase letters from string <span class="tt">s</span> Note: The transition states for iterative is similar to recursive as well </p><dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">str</td><td>given string, which might not be abbreivated </td></tr>
|
||||
<tr><td class="paramname">result</td><td>resultant abbreivated string </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd><code>false</code> if string <code>str</code> cannot be converted to <code>result</code> </dd>
|
||||
<dl class="section return"><dt>Returns</dt><dd><span class="tt">false</span> if string <span class="tt">str</span> cannot be converted to <span class="tt">result</span> </dd>
|
||||
<dd>
|
||||
<code>true</code> if string <code>str</code> can be converted to <code>result</code> </dd></dl>
|
||||
<span class="tt">true</span> if string <span class="tt">str</span> can be converted to <span class="tt">result</span> </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d7/d73/abbreviation_8cpp_source.html#l00119">119</a> of file <a class="el" href="../../d7/d73/abbreviation_8cpp_source.html">abbreviation.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 119</span> {</div>
|
||||
@@ -286,23 +269,24 @@ Algorithm</h3>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Recursive Dynamic Programming function. </p>
|
||||
<p>Returns whether <code>s</code> can be converted to <code>t</code> with following rules: a. Capitalize zero or more of a's lowercase letters from string <code>s</code> b. remove all other lowercase letters from string <code>s</code> </p><dl class="params"><dt>Parameters</dt><dd>
|
||||
<p>Returns whether <span class="tt">s</span> can be converted to <span class="tt">t</span> with following rules: a. Capitalize zero or more of a's lowercase letters from string <span class="tt">s</span> b. remove all other lowercase letters from string <span class="tt">s</span> </p><dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">memo</td><td>To store the result </td></tr>
|
||||
<tr><td class="paramname">visited</td><td>boolean to check if the result is already computed </td></tr>
|
||||
<tr><td class="paramname">str</td><td>given string, which might not be abbreivated </td></tr>
|
||||
<tr><td class="paramname">result</td><td>resultant abbreivated string </td></tr>
|
||||
<tr><td class="paramname">str_idx</td><td>index for string <code>str</code>, helpful for transitions </td></tr>
|
||||
<tr><td class="paramname">result_idx</td><td>index for string <code>result</code>, helpful for transitions </td></tr>
|
||||
<tr><td class="paramname">str_idx</td><td>index for string <span class="tt">str</span>, helpful for transitions </td></tr>
|
||||
<tr><td class="paramname">result_idx</td><td>index for string <span class="tt">result</span>, helpful for transitions </td></tr>
|
||||
</table>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd><code>false</code> if string <code>str</code> cannot be converted to <code>result</code> </dd>
|
||||
<dl class="section return"><dt>Returns</dt><dd><span class="tt">false</span> if string <span class="tt">str</span> cannot be converted to <span class="tt">result</span> </dd>
|
||||
<dd>
|
||||
<code>true</code> if string <code>str</code> can be converted to <code>result</code> </dd></dl>
|
||||
<p><code>(str[i] == result[j])</code>: if str char at position i is equal to <code>result</code> char at position j, then s character is a capitalized one, move on to next character <code>str[i] - 32 == result[j]</code>: if <code>str[i]</code> character is lowercase of <code>result[j]</code> then explore two possibilites:</p><ol type="1">
|
||||
<li>convert it to capitalized letter and move both to next pointer <code>(i + 1, j + 1)</code></li>
|
||||
<li>Discard the character <code>(str[i])</code> and move to next char <code>(i + 1, j)</code></li>
|
||||
<span class="tt">true</span> if string <span class="tt">str</span> can be converted to <span class="tt">result</span> </dd></dl>
|
||||
<p><span class="tt">(str[i] == result[j])</span>: if str char at position i is equal to <span class="tt">result</span> char at position j, then s character is a capitalized one, move on to next character <span class="tt">str[i] - 32 == result[j]</span>: if <span class="tt">str[i]</span> character is lowercase of <span class="tt">result[j]</span> then explore two possibilites:</p><ol type="1">
|
||||
<li>convert it to capitalized letter and move both to next pointer <span class="tt">(i + 1, j + 1)</span></li>
|
||||
<li>Discard the character <span class="tt">(str[i])</span> and move to next char <span class="tt">(i + 1,
|
||||
j)</span></li>
|
||||
</ol>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d7/d73/abbreviation_8cpp_source.html#l00059">59</a> of file <a class="el" href="../../d7/d73/abbreviation_8cpp_source.html">abbreviation.cpp</a>.</p>
|
||||
@@ -380,7 +364,7 @@ Algorithm</h3>
|
||||
<td class="mlabels-left">
|
||||
<table class="memname">
|
||||
<tr>
|
||||
<td class="memname">static void test </td>
|
||||
<td class="memname">void test </td>
|
||||
<td>(</td>
|
||||
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
|
||||
<td></td>
|
||||
@@ -437,11 +421,19 @@ Algorithm</h3>
|
||||
</div>
|
||||
</div><!-- contents -->
|
||||
</div><!-- doc-content -->
|
||||
<div id="page-nav" class="page-nav-panel">
|
||||
<div id="page-nav-resize-handle"></div>
|
||||
<div id="page-nav-tree">
|
||||
<div id="page-nav-contents">
|
||||
</div><!-- page-nav-contents -->
|
||||
</div><!-- page-nav-tree -->
|
||||
</div><!-- page-nav -->
|
||||
</div><!-- container -->
|
||||
<!-- start footer part -->
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="../../dir_8a20dd5bfd5341a725342bf72b6b686f.html">dynamic_programming</a></li><li class="navelem"><a class="el" href="../../d7/d73/abbreviation_8cpp.html">abbreviation.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.2 </li>
|
||||
<li class="navelem"><a href="../../dir_8a20dd5bfd5341a725342bf72b6b686f.html">dynamic_programming</a></li><li class="navelem"><a href="../../d7/d73/abbreviation_8cpp.html">abbreviation.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user