forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupedWord.html
More file actions
4 lines (4 loc) · 4.3 KB
/
Copy pathGroupedWord.html
File metadata and controls
4 lines (4 loc) · 4.3 KB
1
2
3
4
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>A word is grouped if, for each letter in the word, all occurrences of that letter form exactly one consecutive sequence. In other words, no two equal letters are separated by one or more letters that are different. For example, the words "ccazzzzbb" and "code" are grouped, while "aabbbccb" and "topcoder" are not.</p>
<br></br>
<p>A grouped word was divided into several parts. You are given all the <b>parts</b> in random order as a vector <string>. Reconstruct the original word and return it. If there is more than one possible answer, return "MANY" instead. If no grouped word could have resulted in the given parts, return "IMPOSSIBLE" instead (all quotes for clarity).</p>
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>GroupedWord</td></tr><tr><td>Method:</td><td>restore</td></tr><tr><td>Parameters:</td><td>vector <string></td></tr><tr><td>Returns:</td><td>string</td></tr><tr><td>Method signature:</td><td>string restore(vector <string> parts)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>parts</b> will contain between 1 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>parts</b> will contain between 1 and 20 characters, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>parts</b> will contain only lowercase letters ('a' - 'z').</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"aaa", "a", "aa"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: "aaaaaa"</pre></td></tr><tr><td><table><tr><td colspan="2">These parts could only have come from the word "aaaaaa", which is a grouped word.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"ab", "bba"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: "IMPOSSIBLE"</pre></td></tr><tr><td><table><tr><td colspan="2">The only possible original words are "abbba" and "bbaab", and neither of them are grouped words.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"te", "st"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: "stte"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"te", "s", "t"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: "MANY"</pre></td></tr><tr><td><table><tr><td colspan="2">The initial word could be either "stte" or "ttes".</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"orr", "rd", "woo", "www"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: "wwwwooorrrd"</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">5)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"abcb"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: "IMPOSSIBLE"</pre></td></tr><tr><td></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>