前缀判断
来源:互联网 发布:下载scratch软件 编辑:程序博客网 时间:2024/05/20 19:48
前缀判断
如下的代码判断 needle_start指向的串是否为haystack_start指向的串的前缀,如不是,则返回NULL。
比如:"abcd1234" 就包含了 "abc" 为前缀
#include<iostream>
#include<cstring>using 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; ///需要填写的语句
///++优先级高于*,但由于先用needle++,首地址的内容还可以取到
}if(*needle) return NULL;
return haystack_start;
}
int main()
{
char *p;int i;
char a[10];char b[10];
cin>>a;
cin>>b;p=prefix(a,b);
if(p!=NULL)
for(i=0;i<strlen(a);i++,p++)
cout<<*p;
return 0;
}
0 0
- 前缀判断
- 前缀判断
- 前缀判断
- 前缀判断
- 前缀判断
- 前缀判断
- 前缀判断
- 前缀判断
- poj 1056 判断前缀
- 前缀判断 - 蓝桥杯
- 前缀判断--蓝桥杯
- 1005-前缀判断
- 2013 前缀判断
- 蓝桥 前缀判断
- 蓝桥杯--前缀判断
- sdnu1099.前缀判断
- sdnu 1099 前缀判断
- sdnu oj 1099 前缀判断
- hdu 5641 King's Phone【暴力枚举】
- Multiple annotations found at this line: - cvc-elt.1: Cannot find the declaration of element 'ehcac
- 【翻译自mos文章】已经安装的Oracle database组件和自带的用户信息
- CF #345 Div. 2
- L19函數:我的地盤聽我的
- 前缀判断
- HDU 1503 Advanced Fruits
- IT忍者神龟之在Tomcat配置JNDI数据源的三种方式
- stm32启动文件解析
- Matlab与C++混合编程(依赖OpenCV)
- 天声人語 20160313 農業高校の挑む夢
- Android Studio 使用NDK编程调用第三方动态库问题记录
- 阶段总结(第一周到第四周)
- 枚举大小sizeof 中枚举的大小详解