herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
你會用C的算子sizeof?
-
Python CPP heap priority queue速解L eetcode 2530. Maximal Score After Applying K Operations heap/priority queue是重要的資料結構,無論是C++的std::priority_q...
-
C++ DP動態規劃解Leetcode 937 Maximum Number of Points with Cost 有些標示medium要比標示hard的問題還要難,Leetcode 1937. Maximum Number of Points with Cost,DP動態規...
61 則留言:
public class ex1 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
package hello;
public class ex01 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if(n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,B,C,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(A,B,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
public class ex01 {
static int N=0;
static void hanoi (char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 5);
}
}
package hello;
public class ex01 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if(n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,B,C,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(A,B,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
public class ex1 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if(n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
package hello;
public class ex01 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if(n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,B,C,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(A,B,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
public class hello {
static int N=0;
static void hanoi (char A, char B, char C , int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 4);
}
}
package p1;
public class hw1 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(A,C,B,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
package p1;
public class hw1 {
static int N=0;
static void hanoi(char A, char B, char C, int n){
if(n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
public class hello {
static int N=0;
static void hanoi (char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(A,C,B,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
public class ex01
{
static int N=0;
static void hanoi(int A,int B,int C,int n)
{
if (n==1)
System.out.println("移動"+n+":"+A+"=>"+C);
else
{
hanoi(A,C,B,n-1);
System.out.println("移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args)
{
hanoi(1,2,3,4);
}
}
public class hello {
static int N=0;
static void hanoi (char A, char B, char C , int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 4);
}
}
public class ex12 {
static int N=0;
static void hanoi(char A, char B, char C, int n){
if(n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',4);
}
}
public class a01 {
static int N=0;
static void Hn(char A,char B,char C,int n){
if(n==1)System.out.println("第"+(++N)+"步:\t"+n+"從"+A+"->"+C);
else{
Hn(A,C,B,n-1);
System.out.println("第"+(++N)+"步:\t"+n+"從"+A+"->"+C);
Hn(B,A,C,n-1);
}
}
public static void main(String[] args) {
Hn('A','B','C',4);
}
}
第1步: 1從A->B
第2步: 2從A->C
第3步: 1從B->C
第4步: 3從A->B
第5步: 1從C->A
第6步: 2從C->B
第7步: 1從A->B
第8步: 4從A->C
第9步: 1從B->C
第10步: 2從B->A
第11步: 1從C->A
第12步: 3從B->C
第13步: 1從A->B
第14步: 2從A->C
第15步: 1從B->C
public class hello {
static int N=0;
static void hanoi(char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 5);
}
}
package p1;
public class ex01 {
static int N=0;
static void hanoi(char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動" +n +":" +A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動" +n +":" +A+"=>"+C);
hanoi(B,A,C, n-1);
}
}
public static void main(String[] args)
{
hanoi('A','B','C', 5);
}
}
public class hello {
static int N=0;
static void hanoi (char A, char B, char C , int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 4);
}
}
public class Ex12 {
static int N=0;
static void hanoi(char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
public class hello {
static int N=0;
static void hanoi (char A, char B, char C , int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 4);
}
}
package ererer;
public class ex1 {
static int N=0;
public static void hanoi(int A,int B,int C ,int n) {
if(n==1)
System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi(1,2,3,4);
}
}
public class hello {
static int N=0;
static void hanoi (char A, char B, char C , int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 4);
}
}
package ererer;
public class ex1 {
static int N=0;
public static void hanoi(int A,int B,int C ,int n) {
if(n==1)
System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi(1,2,3,4);
}
}
package ererer;
public class ex1 {
static int N=0;
public static void hanoi(int A,int B,int C ,int n) {
if(n==1)
System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi(1,2,3,4);
}
}
package hello;
public class hello {
static int N=0;
static void hanoi(char A, char B, char C,int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,B,C, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 5);
}
}
package ddt;
public class ttd {
static int N=0;
public static void hanoi(int A,int B,int C,int n)
{
if(n==1)
System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
else
{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+N+":"+A+"=>"+C);
hanoi(B,C,A,n-1);
}
}
public static void main(String[] args) {
hanoi(1,2,3,4);
}
}
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hw1;
public class hello {
static int N=0;
static void hanoi(char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 5);
}
}
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
public class EX01 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[]args){
hanoi('A','B','C',5);
}
}
public class ex {
static int N=0;
static void hanoi(int A, int B, int C, int n){
if (n==1)
System.out.println((++N)+"移動"+n+": "+A+"=>"+C);
else {
hanoi (A,C,B,n-1);
System.out.println((++N)+"移動"+n+": "+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi(1,2,3, 1000);
}
}
public class ex01 {
static int N=0;
public static void hanoi(int A, int B,int C,int n) {
if (n==1)
System.out.println((++N)+"步 "+"移動"+n+"層"+":"+A+"柱=>"+C+"柱");
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+"步 "+"移動"+n+"層"+":"+A+"柱=>"+C+"柱");
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args){
hanoi(1,2,3,4);
}
}
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
public class Ex12 {
static int N=0;
static void hanoi(char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A, C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B, A, C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
public class ex1 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
public class ex1 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
2016年12月26日 下午12:10
匿名 B10233049 黃家崙 提到...
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
2016年12月26日 下午12:10
匿名 B10233049 黃家崙 提到...
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
public class ex01 {
static int N=0;
static void hanoi (char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 5);
}
}
public class ex01 {
static int N=0;
static void hanoi (char A, char B, char C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,C,B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B,A,C, n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C', 5);
}
}
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class ex01 {
static int N=0;
static void hanoi(char A,char B,char C,int n){
if(n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else{
hanoi(A,B,C,n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(A,B,C,n-1);
}
}
public static void main(String[] args) {
hanoi('A','B','C',5);
}
}
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------------------------------------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
package hello;
public class hello{
static int N=0;
static void hanoi(int A,int B, int C, int n){
if (n==1)
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
else
{
hanoi(A , C, B, n-1);
System.out.println((++N)+":移動"+n+":"+A+"=>"+C);
hanoi(B , A, C, n-1);
}
}
public static void main (String[] args){
hanoi (1,2,3, 4);
}
}
------
1:移動1:1=>2
2:移動2:1=>3
3:移動1:2=>3
4:移動3:1=>2
5:移動1:3=>1
6:移動2:3=>2
7:移動1:1=>2
8:移動4:1=>3
9:移動1:2=>3
10:移動2:2=>1
11:移動1:3=>1
12:移動3:2=>3
13:移動1:1=>2
14:移動2:1=>3
15:移動1:2=>3
張貼留言