1. 程式人生 > 其它 >PTA字串的模式匹配

PTA字串的模式匹配

一、題目描述

  

 

 二、解題思路

  簡單做法用c++中的stl中string類的find函式一句話解決

三、程式碼實現

 1 #include "bits/stdc++.h"
 2 #define PII pair<int,int>
 3 #define rep(i,z,n) for(int i = z;i <= n; i++)
 4 #define per(i,n,z) for(int i = n;i >= z; i--)
 5 #define ll long long
 6 #define db double
 7 #define vi vector<int>
 8
#define debug(x) cerr << "!!!" << x << endl; 9 using namespace std; 10 //從某個串中把某個子串替換成另一個子串 11 string& replace_all(string& src, const string& old_value, const string& new_value) { 12 // 每次重新定位起始位置,防止上輪替換後的字串形成新的old_value 13 for (string::size_type pos(0); pos != string
::npos; pos += new_value.length()) { 14 if ((pos = src.find(old_value, pos)) != string::npos) { 15 src.replace(pos, old_value.length(), new_value); 16 } 17 else break; 18 } 19 return src; 20 } 21 inline ll read() 22 { 23 ll s,r; 24 r = 1; 25 s = 0
; 26 char ch = getchar(); 27 while(ch < '0' || ch > '9'){ 28 if(ch == '-') 29 r = -1; 30 ch = getchar(); 31 } 32 while(ch >= '0' && ch <= '9'){ 33 s = (s << 1) + (s << 3) + (ch ^ 48); 34 ch = getchar(); 35 } 36 return s * r; 37 } 38 inline void write(ll x) 39 { 40 if(x < 0) putchar('-'),x = -x; 41 if(x > 9) write(x / 10); 42 putchar(x % 10 + '0'); 43 } 44 int main() 45 { 46 string a,b; 47 int n; 48 n = read(); 49 while(n--){ 50 cin >> a >> b; 51 if(a.find(b) != 0) 52 cout << "Yes" << endl; 53 else 54 cout << "No" << endl; 55 } 56 return 0; 57 }