a53

limbaj

a53
Nov 28th, 2020 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("limbaj.in");
  6. ofstream fout("limbaj.out");
  7.  
  8. int main () {
  9. vector < short > v(26);
  10. for(short &x : v)
  11. fin >> x;
  12. stack < bool > S;
  13. string s;
  14. bool flag;
  15. while(fin >> s) {
  16. flag = true;
  17. if(s.size() == 3 && s[1] == '=') {
  18. v[s[0] - 97] = v[s[2] - 97];
  19. continue;
  20. }
  21. if(s == "if") {
  22. fin >> s;
  23. bool vf = false;
  24. if(s[0] == '=') {
  25. if(v[s[1] - 97] == v[s[2] - 97])
  26. vf = true;
  27. }
  28. if(s[0] == '>') {
  29. if(v[s[1] - 97] > v[s[2] - 97])
  30. vf = true;
  31. }
  32. if(s[0] == '<') {
  33. if(v[s[1] - 97] < v[s[2] - 97])
  34. vf = true;
  35. }
  36. S.emplace(vf);
  37. continue;
  38. }
  39. if(s == "da" && !S.top()) {
  40. flag = false;
  41. string s1;
  42. short cnt = 0;
  43. while(!flag) {
  44. fin >> s1;
  45. if(s1 == "if")
  46. ++cnt;
  47. if(s1 == "fi" && cnt > 0) {
  48. --cnt;
  49. continue;
  50. }
  51. if(s1 == "fi" && cnt == 0) {
  52. S.pop();
  53. flag = true;
  54. }
  55. if(s1 == "nu" && cnt == 0)
  56. flag = true;
  57. }
  58. continue;
  59. }
  60. if(s == "nu" && S.top()) {
  61. flag = false;
  62. string s1;
  63. short cnt = 0;
  64. while(!flag) {
  65. fin >> s1;
  66. if(s1 == "if")
  67. ++cnt;
  68. if(s1 == "fi" && cnt > 0) {
  69. --cnt;
  70. continue;
  71. }
  72. if(s1 == "fi" && cnt == 0) {
  73. S.pop();
  74. flag = true;
  75. }
  76. }
  77. continue;
  78. }
  79. }
  80. for(short x : v)
  81. fout << x << ' ';
  82. }
Add Comment
Please, Sign In to add comment