69,382
社区成员
发帖
与我相关
我的任务
分享
#include "stdio.h"
#include "string.h"
#define N 4
void lookup_keyword(char *desired_word[],char *keyword_table[],int a[],int b[],int *m,int *n )
{
int i,j;
int aCount = 0,bCount = 0;
for(j = 0;j < N;j ++)
{
for(i = 0;i < N;i ++)
{
if(strcmp(keyword_table[j],desired_word[i]) == 0)
{
a[aCount ++] = i;
b[bCount ++] = j;
}
}
}
*m = aCount;
*n = bCount;
}
int main(int argc, char* argv[])
{
char *a_table[N] = {"what","is","you","name"};
char *b_table[N] = {"my","name","is","tom"};
int a[N],b[N];
int i,j,m,n,tag;
lookup_keyword(a_table,b_table,a,b,&m,&n );
//for(i =0;i<m;i++)
// printf("%2d",a[i]);
//printf("\n");
// for(i =0;i<n;i++)
// printf("%2d",b[i]);
//printf("\n");
// printf("%d,%d",m,n);
for(i = 0;i < N;i ++)
{
tag = 0;
for(j = 0;j < m;j ++)
{
if(i == a[j])
tag = 1;
}
if(tag == 0)
printf("%8s",a_table[i]);
}
for(i = 0;i < N;i ++)
{
tag = 0;
for(j =0;j < n;j ++)
{
if(i == b[j])
tag = 1;
}
if(tag == 0)
printf("%8s",b_table[i]);
}
printf("\n");
return 0;
}
// FindString.cpp : 定义控制台应用程序的入口点。
//
#include "stdio.h"
#include "malloc.h"
#include "string.h"
char *maxsubstr(char *str1, char *str2)
{
char *p1, *p2, *q1, *q2, *destp;
char *substr;
int max = 0, len;
p1 = str1;
while(*p1 != '/0')
{
q1 = str2;
while(*q1 != '/0')
{
len = 0;
p2 = p1;
q2 = q1;
while((*p2 != '/0')&&(*q2 != '/0'))
{
if(*p2 == *q2)
{
p2 ++;q2 ++;len ++;
}
else
{
break;
}
}
if(len > max)
{
max = len;
destp =p1;
}
q1++;
}
p1++;
}
substr=(char*)malloc(sizeof(char)*max);
strncpy(substr,destp,max);
return substr;
}
int main()
{
char *s1="aocdfe";
char *s2="pmcdfa";
char *sub;
printf("%s/n%s/n",s1,s2);
sub = maxsubstr(s1,s2);
printf("the max sub string is:%s",sub);
return 0;
}