百强企业2013新校招笔试题(二)
作者:网络转载 发布时间:[ 2013/10/28 10:07:54 ] 推荐标签:面试
一份是C++代码:
[cpp] view plaincopyprint?
//copyright@caopengcs 2013/10月
class Solution {
public:
char *strStr(char *haystack, char *needle) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int i,j;
for (i = j = 0; haystack[i] && needle[j];) {
if (haystack[i] == needle[j]) {
++i;
++j;
}
else {
i = i - j + 1;
j = 0;
}
}
return needle[j]?0:(haystack + i - j);
}
};
//copyright@caopengcs 2013/10月
class Solution {
public:
char *strStr(char *haystack, char *needle) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int i,j;
for (i = j = 0; haystack[i] && needle[j];) {
if (haystack[i] == needle[j]) {
++i;
++j;
}
else {
i = i - j + 1;
j = 0;
}
}
return needle[j]?0:(haystack + i - j);
}
};

sales@spasvo.com