fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. int main() {
  7. int testes, instrucoes, count, n;
  8. char *comando = malloc(10 * sizeof(char));
  9. int *movimento = malloc(10 * sizeof(int));
  10. scanf("%d", &testes);
  11. for (int i = 0; i < testes; i++) {
  12. scanf("%d", &instrucoes);
  13. count = 0;
  14. for (int j = 1; j <= instrucoes; j++) {
  15. scanf("%s", comando);
  16.  
  17. if (comando[0] == 'L') {
  18. count--;
  19. movimento[j] = -1;
  20.  
  21. //printf("%c\n", movimento[j]);
  22. } else if (comando[0] == 'R') {
  23. count++;
  24. movimento[j] = +1;
  25.  
  26. //printf("%c\n", movimento[j]);
  27. } else {
  28. scanf("%*s %d", &n);
  29. movimento[j] = movimento[n];
  30. count += movimento[n];
  31. // printf("%d\n", count);
  32. // printf("%d\n", n);
  33. }
  34.  
  35. }
  36. printf("%d\n", count);
  37. }
  38. free(comando);
  39. free(movimento);
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Standard output is empty