Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int n, pos, OK = 0;
- string a[50][2], cuv, fRule, v;
- cout << "Introdu alfabetul(fara spatii):";
- cin >> v;
- while (OK == 0)
- {
- OK = 1;
- for (int i = 0; i < v.length() - 1; i++)
- for (int j = i + 1; j < v.length(); j++)
- {
- if (v[i] == v[j] && i!=j)
- {
- OK = 0;
- cout << "Alfabetul nu este valid. Introdu alfabetul:";
- cin >> v;
- }
- }
- }
- cout << "Introdu cuvantul pt. prelucrare:";
- cin >> cuv;
- OK = 0;
- while (OK == 0)
- {
- OK = 1;
- for (int i = 0; i < cuv.length();i++)
- if (v.find(cuv[i], 0) == -1 || cuv[i]=='L')
- {
- OK = 0;
- cout << "Cuvantul nu este valid. Introduceti cuvantul:";
- cin >> cuv;
- }
- }
- cout << "Introdu numarul de reguli:";
- cin >> n;
- cout << "Introdu regulile(L pt. Lambda):"<<endl<<endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- cout << "Regula " << i+1 << "." << j+1 << ":";
- cin >> a[i][j];
- }
- cout << endl;
- }
- OK = 1;
- while (OK)
- {
- OK = 0;
- for (int i = 0; i < n; i++)
- {
- if (a[i][0] == "L")
- {
- fRule.insert(0, a[i][1], 1, a[i][1].length() - 1);
- cuv.insert(pos, fRule);
- break;
- }
- else
- {
- if (cuv.find(a[i][0], 0) != -1)
- {
- pos = cuv.find(a[i][0], 0);
- cuv.erase(pos, a[i][0].length());
- if (a[i][1] == "L") OK = 1;
- if (a[i][1] != "L")
- {
- if (a[i][1].find('.') != -1)
- {
- fRule.insert(0, a[i][1], 1, a[i][1].length() - 1);
- cuv.insert(pos, fRule);
- }
- else
- {
- cuv.insert(pos, a[i][1]);
- OK = 1;
- }
- }
- break;
- }
- }
- }
- }
- cout << "Cuvantul modificat este:" << cuv<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement