HDU 2087 剪花布條

剪花布條

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8337    Accepted Submission(s): 5438


Problem Description
一塊花布條,裏面有些圖案,另有一塊直接可用的小飾條,裏面也有一些圖案。對於給定的花布條和小飾條,計算一下能從花布條中儘可能剪出幾塊小飾條來呢?
 

Input
輸入中含有一些數據,分別是成對出現的花布條和小飾條,其布條都是用可見ASCII字符表示的,可見的ASCII字符有多少個,布條的花紋也有多少種花樣。花紋條和小飾條不會超過1000個字符長。如果遇見#字符,則不再進行工作。
 

Output
輸出能從花紋布中剪出的最多小飾條個數,如果一塊都沒有,那就老老實實輸出0,每個結果之間應換行。
 

Sample Input
abcde a3 aaaaaa aa #
 

Sample Output
0 3
 

Author
qianneng
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1711 1686 3746 3336 1358 
 

Statistic | Submit | Discuss | Note

#include<stdio.h>
#include<string.h>
int main()
{
    char str[1010],substr[1010];
    while(scanf("%s",str)&&strcmp(str,"#")!=0)
    {
        scanf("%s",substr);
        int len = strlen(str);
        int sublen = strlen(substr);

        if(len>=sublen)
        {
            int i,j;
            int count = 0;
            for(i=0;i<len;i++)
            {
                j=0;
                while(str[i]==substr[j]&&j<sublen)
                {
                    i++;
                    j++;
                }
                if(j==sublen)
                {count++;i--;}
            }
            printf("%d\n",count);
        }
        else
        {
            printf("0\n");
        }
    }
    return 0;
}

再粘一個:

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int main()
{
    char str1[1010],str2[1010];
    while(scanf("%s",str1)&&(strcmp("#",str1)!=0))
    {
        scanf("%s",str2);
        int cur=0;
        int count=0;
        while(strstr(str1+cur,str2)!=NULL)
        {
            cur=strstr(str1+cur,str2)-str1+strlen(str2);
            count++;
        }
        cout<<count<<endl;
    }

    return 0;
}


發佈了138 篇原創文章 · 獲贊 3 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章