找出两个字符串数组中的相同元素

塞纳河水 2007-12-18 11:57:51
如题目.
...全文
579 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pptor 2007-12-19
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <string.h>
bool a[256]={false};
bool b[256]={false};
void fun(char *c,char *d)
{
int k=strlen(c);
int i=0;
int j;
for(;i<k;i++){j=c[i];a[j]=true;}
k=strlen(d);
for(i=0;i<k;i++){j=d[i];if(a[j]) b[j]=true;}
}
int main()
{
int i=0;
char c[]="The specified location is within the bounds of the object, but not close to the image. For example, a point in the middle";
char d[]="Small, thin, or detailed objects can use this value. ";
fun(c,d);
printf("the same char:\n");
for(;i<256;i++){if(b[i]) printf("%c",i);}
printf("\n");
return 1;
}
塞纳河水 2007-12-19
  • 打赏
  • 举报
回复
能否介绍得更细一点,给出相应代码.
pptor 2007-12-18
  • 打赏
  • 举报
回复
数组a b的长度可根据字符串共有多少种字符
如果字符串不是acill码组成字符串
可以先制造一个对应表
pptor 2007-12-18
  • 打赏
  • 举报
回复
定义2个数组 bool a[256] bool b[256] 初始化都为false
先扫描字符串1出现一个字符x(字符acill 对应的整数值)就把a[x]=true;
再扫描字符串2出现一个字符y(字符acill 对应的整数值)如果a[y]为true 就把b[y]=true;
最后检查下数组b就知道两个字符串数组中的相同元素

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧