fork(9) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n; // Количество ячеек
  6. cin >> n;
  7. string tape(n,0);
  8. int pointer = 0;
  9. string program;
  10. cin >> program;
  11. cout << program << endl;
  12. for (unsigned int i = 0; i < program.length(); i++) {
  13. if (program[i] == '>')
  14. pointer++;
  15.  
  16. if (program[i] == '<')
  17. pointer--;
  18.  
  19. if (program[i] == '+')
  20. tape[pointer]++;
  21.  
  22. if (program[i] == '-')
  23. tape[pointer]--;
  24.  
  25. if (program[i] == '.')
  26. cout << tape[pointer];
  27.  
  28. if (program[i] == ',')
  29. cin >> tape[pointer];
  30.  
  31. if (program[i] == '[') {
  32. if (tape[pointer] == 0) {
  33. int counter = 1;
  34. while (counter > 0) {
  35. i++;
  36. if (program[i] == '[')
  37. counter++;
  38. if (program[i] == ']')
  39. counter--;
  40. }
  41. }
  42. }
  43. else if (program[i] == ']') {
  44. if (tape[pointer] != 0) {
  45. int counter = 1;
  46. while (counter > 0) {
  47. i--;
  48. if (program[i] == '[')
  49. counter--;
  50. if (program[i] == ']')
  51. counter++;
  52. }
  53. }
  54. }
  55. }
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 3420KB
stdin
100
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
stdout
Standard output is empty