Chinaunix
标题:
两道算法题
[打印本页]
作者:
路人乙,在路上
时间:
2008-09-23 17:49
标题:
两道算法题
1. 检查字符串b是否都被a包含。有汉字,GBK。 如果b是有字符重复,在a中出现次数也不少了在b中出现次数。
是返回1,不是返回0
int is_include(char *a,char *b)
{
}
2.seq[a,b……z,aa,ab,......,zz,aaa,aab……,zzz,aaaa,aaab……]
给任意字符串s给出在上述序列中的位置.
for(int j=strlen(s)-1,k=0;j>=0;j--,k++)
index+=seqCh[k]^j;
作者:
xwolff
时间:
2008-09-26 14:55
标题:
第一个问题的代码
#include <stdio.h>
#include <string.h>
int is_include( char *s1, char *s2 );
void main(void)
{
char s1[80], s2[80];
printf("请您输入第一个字符串:\n");
gets(s1);
printf("请您输入第二个字符串:\n");
gets(s2);
if ( is_include(s1, s2) ) printf("字符串1包含字符串2。\n");
else printf("字符串1不包含字符串2。\n");
}
int is_include( char *s1, char *s2 )
{
int i, j, len1, len2;
int cnt = 0;
len1 = strlen(s1);
len2 = strlen(s2);
for ( i = 0; i <= len1 - len2; i++ )
{
if ( s1
== s2[0] )
{
for ( j = 1; j < len2; j++ )
{
if ( s1[i+j] != s2[j] )
{
break;
}
}
}
if ( j == len2 ) cnt++;
}
if ( cnt > 0 ) return 1;
else return 0;
}
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2