-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy path1063.cpp
36 lines (33 loc) · 968 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
#include <stdio.h>
#include <stack>
int main(){
int n, i, j;
char linha[2000];
char entrada[1000], saida[1000];
std::stack<char> pilha;
while(scanf("%d", &n) && n){
for (i = 0; i < n; i++)
scanf(" %c", &entrada[i]);
for (i = 0; i < n; i++)
scanf(" %c", &saida[i]);
entrada[n] = saida[n] = '\0';
i = j = 0;
while(1){
if(!pilha.empty() && j < n && pilha.top() == saida[j]){
pilha.pop();
printf("R");
j++;
}else if(i < n){
pilha.push(entrada[i]);
printf("I");
i++;
}else break;
}
if(pilha.empty()) printf("\n");
else printf(" Impossible\n");
while (!pilha.empty()){
pilha.pop();
}
}
return 0;
}