Re: [問題] 線性規劃問題
看板C_and_CPP (C/C++)作者tropical72 (我的血有鐵的味道...)時間16年前 (2009/09/01 04:02)推噓0(0推 0噓 0→)留言0則, 0人參與討論串2/4 (看更多)
承蒙版上先進給予指教
點醒我 字典檔 可用 Recurive 完成
我花些時間念了 Recurive
寫出碼如下
// ===============================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// ===============================================
//全域變數
char string[200];
// ===============================================
//
bool IsAllRun(char *string, unsigned len)
{
for(unsigned i=0; i<len; i++){
if(string[i]!='z') return false;
}
return true;
}
// ===============================================
//
void Directory(unsigned len)
{
static bool first=true; // 靜態變數
unsigned var_ptr=len-1;
unsigned i=0;
char ch;
if(first) memset(string, 'a', len), first=false;
string[len]=0;
for(ch='a'; ch<='z'; ch++){
string[var_ptr] = ch;
printf("%s\n", string);
}
while(string[var_ptr]=='z') var_ptr--;
if(var_ptr==-1) {
first = true;
return;
}
string[var_ptr] = string[var_ptr] + 1;
for(i=var_ptr+1; i<len; i++) string[i]='a';
Directory(len);
}
// ===============================================
//
void main()
{
Directory(7);
}
// ================================================
code 很醜,我知道(連 pattern 都沒建...)
當初是想 Recursive Function 配上 loop
就能產上 len 內的字典檔
但出現了一個問題..
我寫了一個 a.bat
內容為 Diectory.exe >a.txt
但只要長度大於3的時候就會跳出
在此想請教各位先進
是因為我的 code 有問題?
還是因為有一些其它因素我沒考慮到?
(比如說是 thread 之類的...)
小弟資質愚味 還請指教
謝謝各位
--
if you love me, let it be.
if you don't, let me free.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.165.145
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章