-
Notifications
You must be signed in to change notification settings - Fork 0
/
1063.cpp
47 lines (38 loc) · 858 Bytes
/
1063.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
// fila
int main()
{
int n;
while ((cin >> n) && n)
{
stack<char> s;
s.push(0);
char out[n+1], in[n+1];
for (int i = 0; i < n; i++)
cin >> in[i];
for( int i = 0; i < n; i++)
cin >> out[i];
int i = 0, j = 0;
while (i < n)
{
s.push(in[i++]);
cout << 'I';
if (s.top() == out[j])
{
while (j < n && s.top() == out[j])
{
cout << 'R';
s.pop();
j++;
}
}
}
while (j < n && s.top() == out[j])
{
cout << 'R';
s.pop(), j++;
}
s.top() ? cout << " Impossible\n" : cout << "\n";
}
}