30 lines
569 B
C++
30 lines
569 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
int main() {
|
|
ios::sync_with_stdio(0);
|
|
cin.tie(0);
|
|
|
|
string instructions;
|
|
getline(cin, instructions);
|
|
cin.ignore(1);
|
|
|
|
unordered_map<string, pair<string, string>> locs;
|
|
|
|
string line;
|
|
while (getline(cin, line)) {
|
|
locs[line.substr(0, 3)] = make_pair(line.substr(7, 3), line.substr(12, 3));
|
|
}
|
|
|
|
string current = "AAA";
|
|
int i = 0;
|
|
while (current != "ZZZ") {
|
|
if (instructions[i++ % instructions.length()] == 'L')
|
|
current = locs[current].first;
|
|
else
|
|
current = locs[current].second;
|
|
}
|
|
|
|
cout << i << '\n';
|
|
}
|