File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ string const NOP = " UNRESTORABLE" ;
7
+ string S, T;
8
+
9
+ bool solve (vector<char >& W, int s) {
10
+ for (int i = 0 ; i < s; ++i) {
11
+ if (W[i] == ' ?' ) W[i] = ' a' ;
12
+ }
13
+ for (int i = 0 ; i < T.size (); ++i) {
14
+ if (W[s+i] == ' ?' ) {
15
+ W[s+i] = T[i];
16
+ }
17
+ if (W[s+i] != T[i]) return false ;
18
+ }
19
+ for (int i = s + T.size (); i < S.size (); ++i) {
20
+ if (W[i] == ' ?' ) W[i] = ' a' ;
21
+ }
22
+ return true ;
23
+ }
24
+
25
+ string solve () {
26
+ for (int i = S.size () - T.size (); i >= 0 ; --i) {
27
+ vector<char > W (S.begin (), S.end ());
28
+ if (solve (W, i)) return string (W.begin (), W.end ());
29
+ }
30
+ return NOP;
31
+ }
32
+
33
+ int main () {
34
+ ios_base::sync_with_stdio (false );
35
+ cin.tie (0 ); cout.tie (0 );
36
+
37
+ cin >> S >> T;
38
+ cout << solve () << endl;
39
+
40
+ return 0 ;
41
+ }
You can’t perform that action at this time.
0 commit comments