-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path1063.cpp
More file actions
37 lines (37 loc) · 984 Bytes
/
Copy path1063.cpp
File metadata and controls
37 lines (37 loc) · 984 Bytes
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
// Ivan Carvalho
// Solution to https://www.beecrowd.com.br/judge/problems/view/1063
#include <cstdio>
#define MAX 30
int n, tam;
char saida[MAX], pilha[MAX], entrada[MAX];
void pop() {
if (tam > 0) tam--;
}
void push(char x) { pilha[++tam] = x; }
void clear() { tam = 0; }
char top() { return pilha[tam]; }
int main() {
while (scanf("%d", &n) && n != 0) {
clear();
for (int i = 1; i <= n; i++) scanf(" %c", &entrada[i]);
for (int i = 1; i <= n; i++) scanf(" %c", &saida[i]);
int j = 1;
push(entrada[j++]);
printf("I");
for (int i = 1; i <= n; i++) {
while (top() != saida[i] && j <= n) {
printf("I");
push(entrada[j++]);
}
if (top() == saida[i]) {
printf("R");
pop();
} else {
printf(" Impossible");
break;
}
}
printf("\n");
}
return 0;
}