Overclock.net banner
1 - 4 of 4 Posts

·
Registered
Joined
·
1,012 Posts
Code:

Code:
/* Towers of Hanoi */
/* Decompiled - Overclock.net */
#include <stdio.h>

int hanoi( int disks, int start, int finish, int temp );

int main()
{
  int disks, start, finish, temp;

  printf("Enter the number of disks: ");
  scanf("%d", &disks);
  printf("Enter the starting position ( 1 thru 3 ): ");
  scanf("%d", &start);
  printf("Enter the finishing position ( 1 thru 3 ): ");
  scanf("%d", &finish);
  printf("Enter the temporary position ( 1 thru 3 ): ");
  scanf("%d", &temp);

  hanoi(disks, start, finish, temp);

  return 0;
}

int hanoi( int disks, int start, int finish, int temp )
{
  if (disks > 0){
    hanoi( disks - 1, start, temp, finish );
    move( start, finish);
    hanoi( disks - 1, temp, finish, start );
  }
}

int move( int start, int finish )
{
  printf("move ");
  printf("%d", start);
  printf(" --> ");
  printf("%dn", finish);
}
 

·
Registered
Joined
·
1,012 Posts
Code:

Code:
/* String Permutation */
/* Decompiled - Overclock.net */

import java.util.*;

public class Main {

public static void main(String[] args) {

// Scanner for reading input
Scanner in = new Scanner(System.in);
// Prompt
System.out.println("Enter a string: ");
// Get the value entered
String input = in.nextLine();

// Lower case Output
input = input.toLowerCase();

// Calculate all possible permutations !N
permute("", input);
}

private static void permute(String a, String b) {
// Size of string
int size = b.length();

if (size == 0)
System.out.println(a);
else {
for (int i = 0; i < size; i++)
// Recursive call
permute(a + b.charAt(i), b.substring(0, i)
+ b.substring(i + 1, size));
}
}
}
 
1 - 4 of 4 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top