| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 450 人关注过本帖
标题:判断后一个字符串是否是前一个字符串的子串?帮忙填空
收藏  订阅  推荐  打印 
lzxm160
Rank: 2
等级:注册会员
帖子:97
积分:1126
注册:2006-12-26
判断后一个字符串是否是前一个字符串的子串?帮忙填空

#include<stdio.h>
#include<string.h>
#include<malloc.h>
void main()
{
    char *p1, *p2;
    int i, j, n = 0, leng;
    p1 = (char *)malloc(100);
    p2 = (char *)malloc(100);
    scanf("%s%s", p1, p2);
    printf("%s\t%s\n", p1, p2);
    while (*p1 != *p2 && *p1 != '\0')
        --------;

    leng = strlen(p2);
    while (*p2 != '\0' && *p1 != '\0')
    {
        if (*p1 == *p2)
            ----------;
        p1++;
        p2++;
    }
    printf("n=%d  leng=%d\n", n, leng);
    if (--------------)
        printf("yes\n");
    else
        printf("no\n");
    free(p1);free(p2);

}
搜索更多相关主题的帖子: 字符  leng  printf  填空  
2008-1-8 21:21
camelbupt
Rank: 2
等级:注册会员
帖子:44
积分:550
注册:2007-9-28

void main()
{
    char *p1, *p2;
    int i, j, n = 0, leng;
    p1 = (char *)malloc(100);
    p2 = (char *)malloc(100);
    scanf("%s%s", p1, p2);
    printf("%s\t%s\n", p1, p2);
    while (*p1 != *p2 && *p1 != '\0')
        p1++--------;

    leng = strlen(p2);
    while (*p2 != '\0' && *p1 != '\0')
    {
        if (*p1 == *p2)
            ++n----------;
        p1++;
        p2++;
    }
    printf("n=%d  leng=%d\n", n, leng);
    if (n==leng--------------)
        printf("yes\n");
    else
        printf("no\n");
    free(p1);free(p2);

}
2008-1-8 21:44
camelbupt
Rank: 2
等级:注册会员
帖子:44
积分:550
注册:2007-9-28

#include "stdio.h"
#include "string.h"
#include "stdlib.h"
void main()
{
    char *p1, *p2,*p11,*p22;
    int n = 0, leng;
    p1 = (char *)malloc(100);
    p2 = (char *)malloc(100);
    p11=p1;
    p22=p2;
    scanf("%s%s", p1, p2);
    printf("%s\n%s\n", p1, p2);
    while (*p1 != *p2 && *p1 != '\0')
        p1++;

    leng = strlen(p2);
    while (*p2 != '\0' && *p1 != '\0')
    {
        if (*p1 == *p2)
            ++n;
        p1++;
        p2++;
    }
    printf("n=%d,leng=%d\n", n, leng);
    if (n==leng)
        printf("yes\n");
    else
        printf("no\n");
    free(p11);
    free(p22);
    system("pause");
}
你那个程序有点问题,最后free有点问题,改了一下,似乎ok了^_^
2008-1-8 21:56
無邪的睡脸
Rank: 3Rank: 3
来自:湖北武汉
等级:中级会员
威望:1
帖子:331
积分:3830
注册:2007-9-11

kmp算法!

不要仅为成功而努力.要为做一个有价值的人而努力
kobe24j@sina.com

2008-1-8 22:03
lzxm160
Rank: 2
等级:注册会员
帖子:97
积分:1126
注册:2006-12-26

i和j似乎没有用上  这个是研究生考试题  而且这样调试出来的程序要是主串中有重复的字符串就会出错
2008-1-8 22:32
camelbupt
Rank: 2
等级:注册会员
帖子:44
积分:550
注册:2007-9-28

对头,找个程序很不完善,只能对付简单点的
第一次出现不完整的,后面出现完整的字符串就无法实现功能了
呵呵
2008-1-8 22:38
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.047632 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved