Files
PAT/source/html/a1140.html
T

15 lines
1.8 KiB
HTML

Look-and-say Sequence
<div class="ques-view"><p>Look-and-say sequence is a sequence of integers as the following:</p>
<pre><code>D, D1, D111, D113, D11231, D112213111, ...
</code></pre><p>where <code>D</code> is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For example, the 2nd number means that there is one <code>D</code> in the 1st number, and hence it is <code>D1</code>; the 2nd number consists of one <code>D</code> (corresponding to <code>D1</code>) and one 1 (corresponding to 11), therefore the 3rd number is <code>D111</code>; or since the 4th number is <code>D113</code>, it consists of one <code>D</code>, two 1's, and one 3, so the next number must be <code>D11231</code>. This definition works for <code>D</code> = 1 as well. Now you are supposed to calculate the Nth number in a look-and-say sequence of a given digit <code>D</code>.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case, which gives <code>D</code> (in [0, 9]) and a positive integer N (<span class="katex"><span class="katex-mathml"><math><mrow><mo>≤</mo></mrow>\le</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.63597em;"></span><span class="strut bottom" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mrel">≤</span></span></span></span> 40), separated by a space.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>Print in a line the Nth number in a look-and-say sequence of <code>D</code>.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">1 8
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">1123123111
</code></pre>
</div>