首页 > 其他 > 详细

ACM Binary String Match

时间:2014-02-18 21:43:14      阅读:512      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void SubString(char sub[], char s[], int i, int m)
{
    int j;
    for(j=1; j<=m; j++)
        sub[j]=s[i++];
    sub[j]=NULL; 
}
int main()
{
    char s[1001], c[11], *sub=NULL;
    int num,m,n,i,count;
    scanf("%d", &num);
    while(num--)
    {
        scanf("%s", c+1);
        scanf("%s", s+1);
        m=strlen(c+1);
        n=strlen(s+1);
        sub=(char *)malloc((m+2)*sizeof(char));
        for(i=1,count=0; i<=n-m+1; i++)
        {
            SubString(sub,s,i,m);
            if(!strcmp(c+1,sub+1))
                count++;
        }
        printf("%d\n",count);
    }
    return 1;
}
View Code


写的自我感觉不错!

ACM Binary String Match

原文:http://www.cnblogs.com/the-one/p/3554195.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!