int main() {
    int n = __VERIFIER_nondet_int();
    if (n < 1 || n > 31) {
    	return 0;
    }
    int result = hanoi(n);
    if (result >= 0) {
        return 0;
    } else {
        ERROR: __VERIFIER_error();
    }
}
Пример #2
0
int main()
{
    int n;
    char a = 'X', b = 'Y', c = 'Z';

    printf("请输入汉诺塔的层数:");
    scanf("%d", &n);

    hanoi( n, a, b, c );

    return 0;
}
Пример #3
0
/*
 * This function returns the optimal amount of steps,
 * needed to solve the problem for n-disks
 */
int hanoi(int n) {
    int ret, tmp;
    if (n == 1) {
		/* return 1; */
		ret = 1; goto RET;
	}
	/* return 2 * (hanoi(n-1)) + 1; */
    hanoi(n-1);
    tmp = get_hanoi();
    ret = 2 * tmp + 1;
RET:
    set_hanoi(ret);
}
Пример #4
0
int main(int argc, const char *argv[])
{
    int n = 0;
    
    printf("Please input a number:\n");
    scanf("%d",&n);
    count=0;

    hanoi('A','B','C',n);
    printf("累计次数为:%d\n",count);

    return 0;
}
Пример #5
0
void hanoi(int n, char a, char b, char c){
	int i;
	if(n > 0){
		for(i = 0; i < 4 - n; i++) printf(" ");
		printf("%d in ", n);
		if(n > 1){
			printf("%c %c %c -> %c %c %c\n", a, b, c, a, c, b);
		}else{
			printf("\n");
		}
		hanoi(n - 1, a, c, b);
		for(i = 0; i < 4 - n; i++) printf(" ");
		printf("%d番目の円盤を %c から %c に移動\n", n, a, b);
		if(n > 1){
			for(i = 0; i < 4 - n; i++) printf(" ");
			printf("%c %c %c -> %c %c %c\n", a, b, c, c, b, a);
		}
		hanoi(n - 1, c, b, a);
		for(i = 0; i < 4 - n; i++) printf(" ");
		printf("%d out\n", n);
	}
}
Пример #6
0
int main(int argc, char *argv[])
{
	int N, M;
	if (argc != 3) {
		printf("usage: ./a.out <number_N> <number_M>\n");
		return 0;
	}
	N = atoi(argv[1]);
	M = atoi(argv[2]);
	printf("(N, M) = (%d, %d)\n", N, M);
	printf("answer = %d\n", hanoi(N, M));
	return 0;
}
Пример #7
0
int main(){
	for(int i=1; i<50; i++)
		arr[i]=0ULL;
	arr[0]=0ULL;
	arr[1]=2ULL;
	int t,n;
	scanf("%i", &t);
	for(int i=0; i<t; i++){
		scanf("%i", &n);
		printf("%llu\n", hanoi(n));

	}

}
Пример #8
0
int main(void) {
	printf("= - = - = 汉诺塔求解 = - = - =\n请输入汉诺塔的盘子数:");
	scanf("%d", &hanoiLength);
	while(0 >= hanoiLength) {
		printf("盘子数不能为负值,请重新输入:");
		scanf("%d", &hanoiLength);
	}
	conf = malloc(hanoiLength * sizeof(int));
	init();
	printf("%d汉诺塔的解为:", hanoiLength);
	hanoi(hanoiLength, 2);
	printf("\n");
	system("pause");
	return 0;
}
int main() {
    int n, cases = 0;
    while(scanf("%d %d", &n, &step) == 2) {
        if(n == 0 && step == 0)
            break;
        printf("Problem #%d\n\n", ++cases);
        bAt = bBt = bCt = 0;
        int i;
        for(i = n; i >= 1; i--)
            bA[bAt++] = i;
        print();
        hanoi(n, 'A', 'B', 'C');
    }
    return 0;
}
Пример #10
0
/****************************** main entry *****************************/
int main()
{
	int num=5;
	int X[10]={5,4,3,2,1,0,0,0,0,0};
	int Y[10]={0,0,0,0,0,0,0,0,0,0};
	int Z[10]={0,0,0,0,0,0,0,0,0,0};
	x=X;
	y=Y;
	z=Z;

	displayAll(LENGTH,x,y,z);	//print the tower before operation
	hanoi(num,X,Y,Z);

	return 0;
}
int main() {
    int n = __VERIFIER_nondet_int();
    if (n < 1 || n > 31) {
    	return 0;
    }
    counter = 0;
    applyHanoi(n, 1, 3, 2);
    int result = hanoi(n);
    // result and the counter should be the same!
    if (result == counter) {
        return 0;
    } else {
        ERROR: __VERIFIER_error();
    }
}
Пример #12
0
int main(void)
{
    int i;
    
    printf("枚数 ? ");
    scanf("%d",&N);
    
    //準備
    for(i=0;i<N;i++)
        pie[i][0]=N-i;
    sp[0]=N; sp[1]=0; sp[2]=0;
    
    hanoi(N,0,1,2);
    return 0;
}
Пример #13
0
main()
{
   int n;

   clrscr();
   printf("\n");

   printf(" Numarul de discuri : ");
   scanf("%i", &n);
   printf("\n      Succesiunea de mutari este :\n\n");
   hanoi(n, 'A', 'B', 'C');

   getch();
   return 0;
}
int main(int argc,char *argv[])
{
    int i,N=atoi(argv[1]);

    hanoi(N,1);

    for(i=0; i<ptr; i++) {
        if(array[i]>0)
            printf("+%d ",array[i]);
        if(array[i]<0)
            printf("%d ",array[i]);
    }
    putchar('\n');

    return(0);
}
Пример #15
0
int main(void){
	// 初期化
	init();
	
	hanoi(SIZE, tree1, tree2, tree3);
	
	int i;
	for(i = 0; i < SIZE * 100000000; i++){
		
	}
	
	// 結果表示
	allshow();
	
	return 0;
}
Пример #16
0
int main() {
    int n = nondet();
    if (n < 1 || n > 31) {
    	return 0;
    }
    /* int result = hanoi(n); */
    int result;
    hanoi(n);
    result = get_hanoi();
    if (result >= n) {
        return 0;
    } else {
        ERROR:
        goto ERROR;
    }
}
Пример #17
0
int main(){
	pid_t fork_ret;
	pid_t child;
//	int local_val = 0;
	int state;
	int child_count = 0;

	for(child_count =0; child_count < 10; ++child_count){
//	while(child_count==3){
		fork_ret = fork();
//		fork_ret = fork();
//		fork_ret = fork();
//		fork_ret = fork();

		if(fork_ret < 0){
			printf("fork() error\n");
			exit(-1);
//			child_count--;
		}
		else if(0==fork_ret){
//		global_val++;
//		local_val++;
//			child_count++;
			hanoi('A', 'B', 'C', 100);
			printf("Child Num.: %d CHILD - PID : %d parent's PID : %d \n",child_count,  getpid(), getpid());
		}
		else{
//		global_val = global_val + 5;
//		local_val = local_val + 5;
//			--child_count;
			printf("PARENT - PID : %d child's PID : %d \n", getpid(), fork_ret);

			child = wait(&state);
			printf("\t Child PID = %d \n", child);
			exit(0);
//		printf("\t return value = %d \n", WEXITSTATUS(state));

//			sleep(10);

//			printf("\t create %d child.\n", child_count);
		}
	}
//	printf("\t global_val : %d \n", global_val);
//	printf("\t local_val : %d \n", local_val);

	return 0;
}
Пример #18
0
int main(void){

        
	char com='1';
	char aux='2';
	char fin='3';
	int n;

	//printf("\nN??mero de discos: ");
	scanf("%d",&n);
	fflush(stdin);

	//printf("\n\nLos movimientos a realizar son: \n");
	hanoi(n,com,aux,fin);
	
	return 0;
}
Пример #19
0
int main()
{
int SIZE;
FILE *input;

input = fopen("hanoiIn.txt","r");
fscanf(input,"%d",&SIZE);

FILE *output;
output = fopen("hanoiOut.txt","w");

hanoi(SIZE,'A','B','C',output);

fclose(input);
fclose(output);
return 0;
}
Пример #20
0
int main() {
    int n;
    int init;
    int aux;
    int fin;
    printf("Enter the number of disks\n");
    scanf("%d", &n);
    printf("Enter initial\n");
    scanf("%d", &init);
    printf("Enter final\n");
    scanf("%d", &fin);
    printf("Enter auxiliary\n");
    scanf("%d", &aux);
    hanoi(n,init,fin,aux);
    return 0;


}
Пример #21
0
void main(void) {
    int n;
    printf("Please input number =>");
    scanf("%d", &n);                    /*讀入數字*/

    if (n > 20) {
        printf("The calucation time will be too long to wait...");
        exit(1);
    }

    if (n < 0) {            /*小於零之數不合法*/
        printf("input error,number must > 0");
        exit(1);
    }

    hanoi(n, 'A', 'B', 'C');
    printf("結束\n");
}
Пример #22
0
int main ()
{
   int numerodischi;

   do
   {
      printf ("Numero di dischi sul piolo di partenza? : ");
      scanf ("%d", &numerodischi);
      if (numerodischi > 10)
         printf ("massimo numero di dischi = %d\n", MAXDISCHI);
   } while (numerodischi > 10);
   while (getchar() != '\n');

   inizializza_pioli (numerodischi);
   hanoi (numerodischi, 0, 2, 1);

   return EXIT_SUCCESS;
}
Пример #23
0
    int main()
    {  int **p;
       int A=0,B=1,C=2;

        printf("       *********** Les Tours de Hanoi  ************\n\n");
        printf("       *****  Developper par:  AYMEN BEN MHAMED & OMAR SAAD  ******\n\n");
        printf("       *************  Amphi:B ************ \n\n");
        printf("       *************  groupe:3 & 2 ************\n\n");
        printf("       Donner le nombre des anneuax ? : " );
        scanf("%d", &N);

        p = liretour(N);
        printf("\n\n" );
        affichetour(p, N);

        hanoi(p, N, A,B,C);

        printf("\n\n     le nombre d'operation est egale a: %d \n\n", cpt);
        system("pause");
        return 0;

    }
Пример #24
0
int main(void)
{
	hanoi(6, 'A','B','C');
	return EXIT_SUCCESS;
}
Пример #25
0
void hanoi_main(){
	printf("\n");
	printf("\n");
	int n = 4;
 	hanoi(n, 'a', 'b', 'c');
}
Пример #26
0
int main(){
	int n;
	scanf("%d",&n);
	hanoi(n, 'a', 'b', 'c');
	return 0;
}
Пример #27
0
/**
 * 1-1-2
 */
int main(int argc, char *argv[])
{
	hanoi(4,'A','B','C');
	return 0;
}
Пример #28
0
int main(){

  hanoi('X', 'Y', 'Z', 3);

  return 0;
}
Пример #29
0
Problem3::Problem3 (int n) {
  hanoi('A', 'C', 'B', n);
}
Пример #30
0
int hanoi(int n){
    if(n==1) return 1;
    else return 2 * hanoi(n-1) + 1;
}