HDU 2087 剪花布條

2021-08-23 12:06:19 字數 1573 閱讀 4462

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

input

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

output

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

sample input

abcde a3

aaaaaa aa

#

sample output

0

3

題目源自網路

給出不超過兩個1000個字元長的字串s1和s2,尋找s1中有幾個s2,遇#輸入結束。

從字串s1起點開始尋找,如果找到,從該點+s2的長度後的那點開始複製到s1結束,重複這個過程,直到s1搜尋結束。可以利用string庫函式裡的find()函式(查詢s2在s1中第一次出現的起始位址)和substr()函式(複製原字串從某點開始,直到結束或者是特定長度,形成新字串)。

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

#define rep(i, a, b) for(int i=(a); i<(b); i++)

#define req(i, a, b) for(int i=(a); i<=(b); i++)

#define ull unsigned __int64

#define sc(t) scanf("%d",&(t))

#define sc2(t,x) scanf("%d%d",&(t),&(x))

#define pr(t) printf("%d\n",(t))

#define pf printf

#define prk printf("\n")

#define pi acos(-1.0)

#define ms(a,b) memset((a),(b),sizeof((a)))

#define mc(a,b) memcpy((a),(b),sizeof((a)))

#define w while

typedef

long

long ll;

typedef

vector

vi;

string s1, s2;

int ans;

int main()

pr(ans);

getchar();

}return

0;}

hdu 2087 剪花布條

include include includeusing namespace std const int maxn 1004 char str maxn str1 maxn int main printf d n count return 0 此題主要是strstr 函式的應用!據說也可以用kmp來...

hdu 2087 剪花布條

題目鏈結 problem description 一塊花布條,裡面有些圖案,另有一塊直接可用的小飾條,裡面也有一些圖案。對於給定的花布條和小飾條,計算一下能從花布條中盡可能剪出幾塊小飾條來呢?input 輸入中含有一些資料,分別是成對出現的花布條和小飾條,其布條都是用可見ascii字元表示的,可見的...

HDU 2087剪花布條

一塊花布條,裡面有些圖案,另有一塊直接可用的小飾條,裡面也有一些圖案。對於給定的花布條和小飾條,計算一下能從花布條中盡可能剪出幾塊小飾條來呢?input 輸入中含有一些資料,分別是成對出現的花布條和小飾條,其布條都是用可見ascii字元表示的,可見的ascii字元有多少個,布條的花紋也有多少種花樣。...