字符串交集 [英] String intersection

查看:48
本文介绍了字符串交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何检查字符串交集?似乎没有一个

库函数,例如:


+ #include< linux / string.h>

+

+ / * AND''ing两个字符串(检查交集)* /

+ static int strand(char * s1,char * s2 )

+ {

+ int i,j;

+ int slen1 = strlen(s1);

+ int slen2 = strlen(s2);

+

+ for(i = 0; i< slen1; i ++)

+ for (j = 0; j< slen2; j ++)

+ if(s1 [i] == s2 [j])

+返回1;

+返回0;

+}


谢谢,

Bahadir

Hi,

How do you check string intersection? There doesn''t seem to be a
library function to do that, e.g:

+#include <linux/string.h>
+
+/* AND''ing two strings (checks intersection) */
+static int strand(char *s1, char *s2)
+{
+ int i, j;
+ int slen1 = strlen(s1);
+ int slen2 = strlen(s2);
+
+ for(i = 0; i < slen1; i++)
+ for(j = 0; j < slen2; j++)
+ if (s1[i] == s2[j])
+ return 1;
+ return 0;
+}

Thanks,
Bahadir

推荐答案

ba ******* *****@gmail.com 写道:




如何检查字符串路口?似乎没有一个

库函数,例如:


+ #include< linux / string.h>
Hi,

How do you check string intersection? There doesn''t seem to be a
library function to do that, e.g:

+#include <linux/string.h>



这是什么?

What''s this?


+ / * AND''ing two strings(check intersection) )* /

+ static int strand(char * s1,char * s2)

+ {

+ int i,j;

+ int slen1 = strlen(s1);

+ int slen2 = strlen(s2);

+

+ for(i = 0; i< slen1; i ++)

+ for(j = 0; j< slen2; j ++)

+ if(s1 [i] == s2 [j])

+返回1;

+返回0;

+}
+/* AND''ing two strings (checks intersection) */
+static int strand(char *s1, char *s2)
+{
+ int i, j;
+ int slen1 = strlen(s1);
+ int slen2 = strlen(s2);
+
+ for(i = 0; i < slen1; i++)
+ for(j = 0; j < slen2; j++)
+ if (s1[i] == s2[j])
+ return 1;
+ return 0;
+}



如何(未经测试):


#include< string.h>

static int strand(const char * s1, const char * s2){

返回strcspn(s1,s2)< strlen(s1);

}


-

Eric Sosman
es ***** @ ieee-dot-org.inva 盖子


Eric Sosman写道:
Eric Sosman wrote:

Bahadir Balban写道:
Bahadir Balban wrote:

>你如何检查字符串交集?似乎没有一个
库函数,例如:

+ #include< linux / string.h>
>How do you check string intersection? There doesn''t seem to be a
library function to do that, e.g:

+#include <linux/string.h>



这是什么?


What''s this?



它看起来像一个非标准的包含指令,前面带有''+''

http://lxr.linux.no/source/include/linux/string.h


Eric Sosman写道:
Eric Sosman wrote:
ba ************ @ gmail.com 写道:
ba************@gmail.com wrote:

>>

你如何检查字符串交集?似乎没有一个
库函数,例如:
>>Hi,

How do you check string intersection? There doesn''t seem to be a
library function to do that, e.g:



如何(未经测试):

#include< string.h>

static int strand(const char * s1,const char * s2){

返回strcspn(s1,s2) )< strlen(s1);

}


How about (untested):

#include <string.h>
static int strand(const char *s1, const char *s2) {
return strcspn(s1, s2) < strlen(s1);
}



#include< string.h>

static int strand( const char * s1,const char * s2){

返回s1 [strcspn(s1,s2)]!=''\ 0'';

}

#include <string.h>
static int strand(const char *s1, const char *s2) {
return s1 [strcspn(s1, s2)] != ''\0'';
}


这篇关于字符串交集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆