<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>





<style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style>
<style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style> <style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document"><title>top coder practice room(practice room1-16)(2001 invi-semi)</title>

<style>
<!--
table.MsoTableGrid
	{border:1.0pt solid windowtext;
	text-align:justify;
	text-justify:inter-ideograph;
	font-size:10.0pt;
	font-family:"Times New Roman";
	}
 li.MsoNormal
	{mso-style-parent:"";
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";
	margin-left:0cm; margin-right:0cm; margin-top:0cm}
-->
</style>
<style type="text/css">
      <!--
        body { font-family: Monospaced; font-size: 12pt }
        pre { font-family: Monospaced; font-size: 12pt }
      -->
    </style><style type="text/css">
      <!--
        body { font-family: Monospaced; font-size: 12pt }
        pre { font-family: Monospaced; font-size: 12pt }
      -->
    </style><style type="text/css">
      <!--
        body { font-size: 12pt; font-family: Monospaced }
        pre { font-size: 12pt; font-family: Monospaced }
      -->
    </style></head><body rightmargin="1" bottommargin="1" marginheight="1" marginwidth="1">



<p align="left"><span lang="en-ca"><font color="#ff0000" size="6"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
TopCoder practice room (purely for fun)</b></font></span></p>Problem Statement<br>
&nbsp;&nbsp;&nbsp; <br>
You have N balls, where N is odd. The balls are numbered from 0 to N-1.
In that order, they are arranged into a row going from the left to the
right.<br>
<br>
In addition to the number, each ball has either the word "left" or the
word "right" written on it. For simplicity, we will use the character
'&lt;' instead of "left", and the character '&gt;' instead of "right".
You are given the labels on all balls as the string label. For each i,
character i of label represents the word on ball i.<br>
<br>
You will now repeat the following procedure:<br>
Choose a ball that is not at either end of the row of balls.<br>
If the chosen ball has the label '&lt;', remove the chosen ball and
also the ball immediately to the left of it. Otherwise, remove the
chosen ball and also the ball to the right of it.<br>
Without reordering the remaining balls, push them together to get rid of the gap created in the previous step.<br>
The process ends when only one ball remains in the row. That ball is
called the survivor. Note that the numbers on the balls do not change
during the process.<br>
<br>
Find all possible survivors. Your method must return a string
containing exactly N characters. If ball i can be the survivor,
character i of the return value must be 'o' (lowercase oh). Otherwise,
the corresponding character must be '.' (a period).<br>
Definition<br>
&nbsp;&nbsp;&nbsp; <br>
Class:<br>
BallRemoval<br>
Method:<br>
canLeave<br>
Parameters:<br>
string<br>
Returns:<br>
string<br>
Method signature:<br>
string canLeave(string label)<br>
(be sure your method is public)<br>
Limits<br>
&nbsp;&nbsp;&nbsp; <br>
Time limit (s):<br>
2.000<br>
Memory limit (MB):<br>
64<br>
Constraints<br>
-<br>
label will contain between 3 and 49 characters, inclusive.<br>
-<br>
label will contain an odd number of characters.<br>
-<br>
Each character of label will be either '&gt;' or '&lt;'.<br>
Examples<br>
0)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
"&lt;&lt;&gt;"<br>
Returns: "..o"<br>
Initially, you have three balls. Since you cannot choose balls at the
ends of the row, you have to choose ball 1. As its label is '&lt;', you
remove balls 0 and 1. Hence the only possible survivor is ball 2.<br>
1)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
"&gt;&gt;&gt;&lt;&lt;"<br>
Returns: "o...o"<br>
If you choose ball 2 or ball 3 first, you have to choose ball 1 next,
and the survivor will be ball 0. If you choose ball 1 first, you have
to choose ball 3 next, and the survivor will be ball 4.<br>
2)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
"&lt;&lt;&gt;&lt;&lt;" <br>
Returns: "....o"<br>
<br>
3)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
"&lt;&gt;&lt;&lt;&gt;&lt;&gt;"<br>
Returns: "o.....o"<br>
<br>
4)<br>
<br>
&nbsp;&nbsp;&nbsp; <br>
"&gt;&gt;&gt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&lt;&lt;&lt;&gt;"<br>
Returns: "o.....o.o.....o"<br>
//////////////////////////////////////////////////////////////////////////////////<br>
#include &lt;string&gt;<br>
#include &lt;vector&gt;<br>
<br>
using namespace std;<br>
<br>
class BallRemoval<br>
{<br>
public:<br>
&nbsp;&nbsp;&nbsp; void findIndex(const string&amp; label, vector&lt;int&gt; array, string&amp; result)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (array.size() == 1)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; result[array[0]] = 'o';<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (size_t i = 1; i &lt; array.size() - 1; i ++)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vector&lt;int&gt; subArray(array);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (label[array[i]] == '&lt;')<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; subArray.erase(subArray.begin() + i-1,
subArray.begin() + i+1);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; subArray.erase(subArray.begin() + i,
subArray.begin() + i+2);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; findIndex(label, subArray, result);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; string canLeave(string label)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vector&lt;int&gt; array;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; string result;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (size_t i = 0; i &lt; label.size(); i ++)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; result.push_back('.');<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; array.push_back(i);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; findIndex(label, array, result);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp; }<br>
};<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;</p>

</body></html>