HDU 2087 剪花布条

http://acm.hdu.edu.cn/showproblem.php?pid=2087

剪花布条

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

Problem Description
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?

Input
输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。

Output
输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。

Sample Input
abcde a3
aaaaaa aa
#

Sample Output
0
3

/* HDU 2087 剪花布条 http://acm.hdu.edu.cn/showproblem.php?pid=2087 */
#include<stdio.h> 
#include<string.h> 
#include <iostream>
#include <string>
#include<algorithm> 
#include <sstream>
#include <set>

#define MAXN 10005 

using namespace std;  

int main()  
{  
    //freopen("in.txt","r",stdin);
    string s1 , s2 ;
    while(cin >> s1)
    {
        if(s1 == "#")
            break;
        cin >> s2 ;

        if(s1.find(s2) != string::npos)
        {
            int len2 = s2.size();
            int cnt = 0;
            while((int)s1.size() >= len2)
            {
                if(s1.find(s2) != string::npos)
                {
                    cnt ++;
                    int pos = s1.find_first_of(s2);
                    s1 = s1.substr(pos+len2);
                }else{
                    break;
                }
            }
            cout << cnt << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;  
}  

你可能感兴趣的:(HDU 2087 剪花布条)