Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n, pos, OK = 0;
  9. string a[50][2], cuv, fRule, v;
  10. cout << "Introdu alfabetul(fara spatii):";
  11. cin >> v;
  12. while (OK == 0)
  13. {
  14. OK = 1;
  15. for (int i = 0; i < v.length() - 1; i++)
  16. for (int j = i + 1; j < v.length(); j++)
  17. {
  18. if (v[i] == v[j] && i!=j)
  19. {
  20. OK = 0;
  21. cout << "Alfabetul nu este valid. Introdu alfabetul:";
  22. cin >> v;
  23. }
  24. }
  25. }
  26. cout << "Introdu cuvantul pt. prelucrare:";
  27. cin >> cuv;
  28. OK = 0;
  29. while (OK == 0)
  30. {
  31. OK = 1;
  32. for (int i = 0; i < cuv.length();i++)
  33. if (v.find(cuv[i], 0) == -1 || cuv[i]=='L')
  34. {
  35. OK = 0;
  36. cout << "Cuvantul nu este valid. Introduceti cuvantul:";
  37. cin >> cuv;
  38. }
  39. }
  40. cout << "Introdu numarul de reguli:";
  41. cin >> n;
  42. cout << "Introdu regulile(L pt. Lambda):"<<endl<<endl;
  43. for (int i = 0; i < n; i++)
  44. {
  45. for (int j = 0; j < 2; j++)
  46. {
  47. cout << "Regula " << i+1 << "." << j+1 << ":";
  48. cin >> a[i][j];
  49. }
  50. cout << endl;
  51. }
  52. OK = 1;
  53. while (OK)
  54. {
  55. OK = 0;
  56. for (int i = 0; i < n; i++)
  57. {
  58. if (a[i][0] == "L")
  59. {
  60. fRule.insert(0, a[i][1], 1, a[i][1].length() - 1);
  61. cuv.insert(pos, fRule);
  62. break;
  63. }
  64. else
  65. {
  66. if (cuv.find(a[i][0], 0) != -1)
  67. {
  68. pos = cuv.find(a[i][0], 0);
  69. cuv.erase(pos, a[i][0].length());
  70. if (a[i][1] == "L") OK = 1;
  71. if (a[i][1] != "L")
  72. {
  73. if (a[i][1].find('.') != -1)
  74. {
  75. fRule.insert(0, a[i][1], 1, a[i][1].length() - 1);
  76. cuv.insert(pos, fRule);
  77. }
  78. else
  79. {
  80. cuv.insert(pos, a[i][1]);
  81. OK = 1;
  82. }
  83. }
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. cout << "Cuvantul modificat este:" << cuv<<endl;
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement