首页 新闻 搜索 专区 学院

程序员求职题目

0
悬赏园豆:200 [已解决问题] 解决于 2008-10-23 21:57
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">&nbsp; </span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">分析一个字符串,分析出字符串中的</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">情况,被</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">"[]" </span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">包围的字符串就是一个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,一个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">"[]"</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中可能包含多个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,以</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">"," </span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">或者</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"> " "(</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">空格</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">)</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">分隔,</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">如果</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是用引号包含的则忽略其中的空格。</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子说明</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br />lable</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是一个字符串,下面的例子中简单起见用了</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">a</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">b</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">c</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">等简单的字符,不要误解成就是一个字母</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子中的</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">somthing</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">就是任意的可包含回车,换行等字符的字符串。</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">1<br />[a]something <br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">其中</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;"> </span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有一个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">2<br />[a][b]something<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个两个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">3<br />[a,b]something<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个两个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">4<br />[a,b][c]something<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个三个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b<br />c</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">5<br />[a,"b b"][cc]something<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个三个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b b<br />cc</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">6<br />[a,"b b",cc]something<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个三个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b b<br />cc</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例子</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">7<br />[a,b b][cc]something<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个四个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b<br />b<br />cc</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">需要支持全角比如</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">"</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">【】</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">" label </span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">分隔符</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">","</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">也要支持全角</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">"</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">"<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">例如</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">【</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">a</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">】</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">[b]somthing<br />&nbsp;</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个两个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">【</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">a</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">b</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">】</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">[c]somthing<br />&nbsp;</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个字符串有个三个</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label: <br />a<br />b<br />c</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">&nbsp;</span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan;" align="left"><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">请用</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">C#</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">写一个分析字符串</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的小函数</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br />List&lt;string&gt; parseLabels(string inputString)<br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">根据输入的字符串返回字符串中含有的</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US">label</span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"><br /></span><span style="font-size: 9.5pt; font-family: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">要求代码清晰,可读性好,如果算法比较复杂请给出适当的算法说明</span><span style="font-size: 9.5pt; font-family: Arial; mso-font-kerning: 0pt;" lang="EN-US"></span></p>
Raul.Z的主页 Raul.Z | 初学一级 | 园豆:5
提问于:2008-10-22 21:00
< >
分享
最佳答案
0

我的解法如下:

 

Code

 

但有个小问题,因为是就近原则所以....
还是看下面这个吧

“["adfa,[[]]【aadfa】”我们希望是|"adfa|,|[[|,|aadfa|,但实际上他什么也拿不到因为引号没有结束,如果在最后面加个引号,他会拿到引号后面的所有,而实际上答案应该和上面的一样

howard-Wang | 菜鸟二级 |园豆:415 | 2008-10-23 00:04
其他回答(1)
0

写多点字会死啊

写个正则就好了

public string GetLable()

{

Regex regex = new regex ("label");

return  regex.match(inputString).ToString();

小眼睛老鼠 | 园豆:2779 (老鸟四级) | 2008-10-22 22:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册