Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void muralha(int moedas, int n, int x, int y,
  5. int oldn, int count, int oldx);
  6. int main()
  7. {
  8. int n;
  9. scanf("%d\n", &n);
  10.  
  11. muralha(0, n, 0, 0, 0, 0, 0);
  12.  
  13. return 0;
  14. }
  15.  
  16. void muralha(int moedas, int n, int x, int y,
  17. int oldn, int count, int oldx)
  18. {
  19. if(count == n){
  20. printf("%d\n", moedas);
  21. return;
  22. }
  23.  
  24. char c;
  25. scanf("%c\n", &c);
  26.  
  27.  
  28. if(c == 'C'){
  29. y+=1;
  30. }else if(c == 'D'){
  31. x+=1;
  32. }
  33.  
  34. int temp = y-x;
  35.  
  36.  
  37. if(abs(temp)==1 && oldn == 0 && count > 0 && temp != oldx){
  38.  
  39. moedas+=1;
  40. }
  41.  
  42. oldx = oldn;
  43. muralha(moedas, n, x, y, temp, count+1, oldx);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement