--- title: 2E 拼接黏貼(Easy) tags: solution --- # E. 拼接黏貼(Easy) 用一個used的bool陣列,去紀錄字串上的那些字元是否已經有被用過了, 其他的抓字串方法就是用最理所當然的雙迴圈窮舉了 (對於每個A字串,檢查S字串的字元並替換成B字串) ```cpp= # include <iostream> using namespace std; int main(){ string s,s1,s2; int N,x,y; bool used[30] = {0}; bool match; cin>>s>>N; while(N--){ cin>>s1>>s2; for(x = 0 ; x<s.size() ; x++){ match = true; for(y = 0 ; match && y<s1.size() ; y++) if(x+y >= s.size() || s1[y] != s[x+y] || used[x+y]) match = false; if(match){ for(y = 0 ; y<s2.size() ; y++){ s[x+y] = s2[y]; used[x+y] = true; } break; } } } cout<<s; } ```