language: C++ 4.7.2 (gcc-4.7.2)
date: 121 days 17 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<stdio.h>
//#include<conio.h>
#include<stack>
using namespace std;
    stack <int> arr;
    stack <int> brr;
    stack <int> crr;
int sum=0;
void func(int n,int present,int usable,int final)
{
     int i;
    if(n==0)
    return;
    
    
    func(n-1,present,final,usable);
    
    if(present==1 && final==2)
    {brr.push(arr.top());arr.pop();}
    else if(present==1 && final==3)
    {crr.push(arr.top());arr.pop();}
    else if(present==2 && final==1)
    {arr.push(brr.top());brr.pop();}
    else if(present==2 && final==3)
    {crr.push(brr.top());brr.pop();}
    else if(present==3 && final==1)
    {arr.push(crr.top());crr.pop();}
    else if(present==3 && final==2)
    {brr.push(crr.top());crr.pop();}
    
    sum=sum+1;
    printf("1->");
    for(i=0;i<arr.size();i++)
    printf("%d ",arr[i]);
    printf("\n");
    printf("2->");
    for(i=0;i<brr.size();i++)
    printf("%d ",brr[i]);
    printf("\n");
    printf("3->");
    for(i=0;i<crr.size();i++)
    printf("%d ",crr[i]);
    printf("\n\n");
    func(n-1,usable,present,final);
}
 
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=n;i>0;i--)
    arr.push(i);
    func(n,1,2,3);
    printf("%d",sum);
    //getch();
}
 
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