快速业务通道

D??ó??3ìDò?±??ìaò??ò?°·???

作者 佚名技术 来源 程序设计 浏览 发布时间 2012-06-29

??ìa?-??£o

Problem statement

You must work out a super string class, String, that is derived from the C++ standard class string. This derived String class must add two new member functions

1; a pattern recognition function that returns the number of occurrences of a string pattern in a string. This function must use operator overloading of the / (division) operator.

2; a function get_token that returns tokens extracted from the string

A token is a substring occurring between space characters in the string or between space characters and the end of the string. The string " aaa bbb cc " has the tokens "aaa", "bbb", and "cc" . When the function is called the first time, it must return "aaa", the next time "bbb", and then "cc". When it is called the 4th time it must return an empty string, and when it is called the 5th time it starts all over returning "aaa". Optionally, you may extend the solution so that tokens may be separated by any character out of a set of character given as a string argument.

2???ò???£o

?êìa?èê?£o

??±?D?′′?¨ò???1|?ü??′óμ?′?′|àíàà£?String£??a??àà±?D?′ó C++ ?D±ê×?μ? string àà?ééú£?±?D??ú???ééúàà?Dìí?óá???3é?±oˉêy£o

1?¢?£ê?ê?±eoˉêy£?·μ???3??′??D???¨′??£ê?μ?3???′?êy?£??oˉêy±?D?ê1ó? / £¨3y·¨£?????·??????£

2?¢ó?oˉêy get_token ′ó′??D?üè??3????o?2¢·μ??????o??£

??o???×?·?′?μ?ò???×ó′?£??ü??óú×?·?′?μ?????????£??ò????óú????oí′??2?????£è?£o×?·?′?“ aaa bbb cc ”?Dμ???o?óD“aaa”?¢“bbb”oí“cc”?£μ±μúò?′?μ÷ó???oˉêyê±£??ü±?D?·μ??“aaa”£???′??ùμ÷ó?ê±·μ??“bbb”£?μúèy′?μ÷ó?ê±·μ??“cc”£?òà′?ààí??£μ±μú??′?μ÷ó???oˉêyê±£??ü±?D?·μ??ò?????′?£?×?oóμ±μú??′?μ÷ó??üê±£?·μ???á1?ó?′ó “aaa” ?aê??£???éò???òaà??1?a???a??·?°?£?è???o??éò?ó??3×é×?·?ò?íaμ?è?o?×?·?·???£??a×é×?·??éò?×÷?aò???′?2?êy′?μY?£

??·¨·???£¨D′3é′ú??£?£o

int CMyString::operator/ (const String& sub)
{
??if(sub.IsEmpty())
??????return 0;
??int count=0;????????//sub?ú×?·?′??Dμ?3???′?êycount
??int ret=Find(sub);????//?¨?ú±?á?ret
??if(ret==-1)
???? return 0;
??else if(ret<=GetLength())
??{
????do

??????count++;
??????ret=Find(sub,GetAt(ret));
????}
?????? while(ret!=-1)
???? }
?? return count;
}
CString CMyString::get_token()
{
?? static int callednum=0;????//callednum?í????oˉêyμ?±?μ÷ó?′?êy
?? int totalnum=operator/('''' '''');????//totalnumê?????μ?×ü??êy
?? if(totalnum==0)
??????return NULL;
?? int tokennum,ret1=0,ret2=0;????//tokennumê?μ?tokenμ?×ü??êy
?? while((ret1=Find('''' '''',ret2))!=-1 &&((ret2=Find('''' '''',ret1))!=-1)
?? {
??????if(ret1==ret2-1)
????????totalnum--;//á????àáúμ???????×÷ò???
??????return??Mid(ret1,ret2-ret1);
?? }
?? if(ret2==-1)
??????return Right(GetLength()-ret1);
????tokennum=totalnum;
?? (callednum++)%=tokennum;
}

éù?÷:?a??ê?′?2úμ???·¨£?òa?????yêμ?????¨1|?ü£??é?ü???úDèòaDT??£??£í???MFCμ?3??§??óD?ù°??ú£?

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号