看板 Prob_Solve 關於我們 聯絡資訊
※ 引述《pnpncat (meow)》之銘言: : ※ 引述《RockLee (Now of all times)》之銘言: : 1. 將A, B, C分別放進stackA, stackB, stackC : 2. 以下列函數判別答案是否為真 : bool foo() { : while ( stackC is not empty ) { : if ( top of stackC == top of stackA ) { : pop stackC; : pop stackA; : } else if (top of stackC == top of stackB ) { : pop stackC; : pop stackB; : } else { : return false; : } : } : return true; : } 我覺得stack 可行 問題就是要解決怎麼re trace stack tempA while C not empty if (top of stackA = top of stackB = top of stackC){ pop C top of A add to end of tempA pop A } else if (top of stackA = top of stackC){ if(tempA is not empty){ top of A add to tempA } pop A pop C } else if (top of B = top of C){ if (tempA is not empty){ if (top of C = top of tempA){ pop tempA } else return false } pop B pop C } else { var temp = pop tempA if(temp = top of B){ push (A, temp) pop B temp = pop B if (top of C != temp) return false pop C } else return false } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 65.30.61.16