现在的位置: 首页 > 综合 > 正文

新加坡程序员考题一则

2017年01月12日 ⁄ 综合 ⁄ 共 1198字 ⁄ 字号 评论关闭
 

考题原文:

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.

参考译文:

问题描述:

你必须创建一个功能强大的串处理类,String,这个类必须从 C++ 中标准的 string 类派生,必须在该派生类中添加两个成员函数:
1、模式识别函数,返回某个串中指定串模式的出现次数。该函数必须使用 / (除法)运算符重载。
2、用函数 get_token 从串中吸取某个记号并返回该记号。

记号指字符串的一个子串,它位于字符串的空格之间,或者位于空格和串尾之间。如:字符串“ aaa bbb cc ”中的记号有“aaa”、“bbb”和“cc”。当第一次调用该函数时,它必须返回“aaa”,下次再调用时返回“bbb”,第三次调用时返回“cc”,依此类推。当第四次调用该函数时,它必须返回一个空串,最后当第五次调用它时,返回结果又从 “aaa” 开始。你可以随意扩展这个解决方案,让记号可以用某组字符以外的任何字符分割,这组字符可以作为一个串参数传递。

抱歉!评论已关闭.