2013 前缀判断

网友投稿 815 2022-11-08

2013 前缀判断

2013 前缀判断

​ 5.char* prefix(char* haystack_start, char* needle_start) { char* haystack = haystack_start; char* needle = needle_start; while(*haystack && *needle){填空位置 } if(*needle) return NULL; return haystack_start; }

如下的代码判断 needle_start指向的串是否为haystack_start指向的串的前缀,如不是,则返回NULL。 比如:"abcd1234" 就包含了 "abc" 为前缀

char* prefix(char* haystack_start, char* needle_start) { char* haystack = haystack_start; char* needle = needle_start; while(*haystack && *needle){ if(----------------) return NULL; //填空位置 } if(*needle) return NULL; return haystack_start; }

请分析代码逻辑,并推测划线处的代码,通过网页提交。 注意:仅把缺少的代码作为答案,千万不要填写多余的代码、符号或说明文字!!

答案:*(haystack++)!=*(needle++)

代码:

#include#include#include#include#define INF 0x3f3f3f3f#define ll long long#define N 10010#define M 1000000007using namespace std;char* prefix(char* haystack_start, char* needle_start){ char* haystack = haystack_start; char* needle = needle_start; while(*haystack && *needle){ if(*(haystack++)!=*(needle++)) return NULL; //填空位置 } if(*needle) return NULL; return haystack_start;}int main(){ char *haystack="abc1234"; char *needle="abc"; printf("%s\n",prefix(haystack,needle)); return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:#1040 : 矩形判断
下一篇:2013 锦标赛
相关文章

 发表评论

暂时没有评论,来抢沙发吧~