• HDU 2087 字符串


    #include <stdio.h>
    #include <string.h>
    
    void main()
    {
        while(1)
        {
            char input1[1000] = {''};
            char input2[1000] = {''};
            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] = {''};
                //在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
    ", count);
        }
    }
  • 相关阅读:
    equals方法
    StringBudilde
    日期
    system
    File类
    calender
    stringbuilder tostring
    File的三种构造方法
    Java入门——day52
    Java入门——day53
  • 原文地址:https://www.cnblogs.com/mrethan/p/4637684.html
Copyright © 2020-2023  润新知