fork download
  1. #include<stdio.h>
  2. //#include<conio.h>
  3. #include<stack>
  4. using namespace std;
  5. stack <int> arr;
  6. stack <int> brr;
  7. stack <int> crr;
  8. int sum=0;
  9. void func(int n,int present,int usable,int final)
  10. {
  11. int i;
  12. if(n==0)
  13. return;
  14.  
  15.  
  16. func(n-1,present,final,usable);
  17.  
  18. if(present==1 && final==2)
  19. {brr.push(arr.top());arr.pop();}
  20. else if(present==1 && final==3)
  21. {crr.push(arr.top());arr.pop();}
  22. else if(present==2 && final==1)
  23. {arr.push(brr.top());brr.pop();}
  24. else if(present==2 && final==3)
  25. {crr.push(brr.top());brr.pop();}
  26. else if(present==3 && final==1)
  27. {arr.push(crr.top());crr.pop();}
  28. else if(present==3 && final==2)
  29. {brr.push(crr.top());crr.pop();}
  30.  
  31. sum=sum+1;
  32. printf("1->");
  33. for(i=0;i<arr.size();i++)
  34. printf("%d ",arr[i]);
  35. printf("\n");
  36. printf("2->");
  37. for(i=0;i<brr.size();i++)
  38. printf("%d ",brr[i]);
  39. printf("\n");
  40. printf("3->");
  41. for(i=0;i<crr.size();i++)
  42. printf("%d ",crr[i]);
  43. printf("\n\n");
  44. func(n-1,usable,present,final);
  45. }
  46.  
  47. int main()
  48. {
  49. int n;
  50. scanf("%d",&n);
  51. for(int i=n;i>0;i--)
  52. arr.push(i);
  53. func(n,1,2,3);
  54. printf("%d",sum);
  55. //getch();
  56. }
  57.  
Compilation error #stdin compilation error #stdout 0.01s 2864KB
stdin
5
compilation info
prog.cpp: In function ‘void func(int, int, int, int)’:
prog.cpp:33: warning: comparison between signed and unsigned integer expressions
prog.cpp:34: error: no match for ‘operator[]’ in ‘arr[i]’
prog.cpp:37: warning: comparison between signed and unsigned integer expressions
prog.cpp:38: error: no match for ‘operator[]’ in ‘brr[i]’
prog.cpp:41: warning: comparison between signed and unsigned integer expressions
prog.cpp:42: error: no match for ‘operator[]’ in ‘crr[i]’
prog.cpp: In function ‘int main()’:
prog.cpp:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout

Standard output is empty