您的位置:首页 > 其它

字符串的包含

2015-10-22 20:34 260 查看
#include<iostream>

#include <stdio.h>

#include <string>

using namespace std;

int getlength(char* a)

{

int length = 0;

while (*a++ != '\0')

{

length++;

}

return length;

}

bool stringcontainer(char* a, char* b)

{

int j = 0;

int ia = getlength(a);

int ib = getlength(b);

for (int i = 0; i <ib; i++)

{

for(j = 0; j < ia&&(b[i]!=a[j]); j++)

;

if (j>=ia)

return false;

}

return true;

}

//测试程序:

int main()

{

char* s1 = "AQWESF";

char* s2 = "ASD";

if (stringcontainer(s1, s2))

cout << "子集" << endl;

else

cout << "不是子集";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: