首页 > 其他 > 详细

HDU 2087 字符串

时间:2015-07-10 23:35:38      阅读:311      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>
#include <string.h>

void main()
{
    while(1)
    {
        char input1[1000] = {\0};
        char input2[1000] = {\0};
        int count = 0;

        scanf("%s", &input1);
        int len1 = (int)strlen(input1);
        if(input1[0] == #)
            return;
        scanf("%s", &input2);
        int len2 = (int)strlen(input2);
        //对input1中的每len2个字符进行遍历
        for(int i = 0; i < len1;)
        {
            char tempBuf[1000] = {\0};
            //在input1中取得len2个连续字符
            for(int j = 0; j < len2; j++)
            {
                if((i + j) < len1)
                    tempBuf[j] = input1[i + j];
                else
                    break;
            }
            //比较
            if(strcmp(tempBuf, input2) == 0)
            {
                count++;
                i += len2;
            }
            else
                i++;
        }
        printf("%d\n", count);
    }
}

 

HDU 2087 字符串

原文:http://www.cnblogs.com/mrethan/p/4637684.html

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