Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main() {
- ifstream Fin;
- ofstream Fout;
- Fin.open("problem1.in");
- Fout.open("problem1.out");
- bool exists = false;
- string s;
- Fin >> s;
- int n, m, k;
- Fin >> n >> m >> k;
- int d[n][n][26];
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- for (int z = 0; z < 26; z++) {
- d[i][j][z] = 0;
- }
- }
- }
- int end[k];
- for (int i = 0; i < k; i++) {
- Fin >> end[i];
- }
- for (int i = 0; i < m; i++) {
- int first, second;
- Fin >> first >> second;
- char word;
- Fin >> word;
- d[first - 1][second - 1][word - 'a'] = 1;
- }
- int currentState = 0;
- for (int j = 0; j < s.size(); j++) {
- bool stateExists = false;
- char currentWord = s[j];
- for (int i = 0; i < n; i++) {
- if (d[currentState][i][currentWord - 'a'] == 1) {
- currentState = i;
- stateExists = true;
- if (j == s.size() - 1) {
- exists = true;
- }
- }
- }
- if (!stateExists) {
- Fout << "Rejects";
- break;
- }
- }
- if (exists) {
- bool contains = false;
- for (int i = 0; i < k; i++) {
- if (end[i] == currentState + 1) {
- contains = true;
- Fout << "Accepts";
- break;
- }
- }
- if (!contains) {
- Fout << "Rejects";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement