Re: [問題] 線性規劃問題
看板C_and_CPP (C/C++)作者tropical72 (我的血有鐵的味道...)時間16年前 (2009/09/02 05:42)推噓0(0推 0噓 0→)留言0則, 0人參與討論串4/4 (看更多)
謝謝各位先進的不吝指教
甚至 snowlike 還花時間寫範例給我看
研究了許久 雖然 recursive 方式沒把字典檔寫出來
但還是以其它方式寫出來了 雖然第一版 code 真的鳥到不行
但還是非常謝謝各位在旁協助指導
最後附上 code ,以感謝各位的指教
// ====================================
// filename: directory.cpp
// author : Edison.Shih.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char string[200];
char end_string[200];
// ====================================
// generate length = len directory
void directory(int len)
{
memset(string, 'a', len);
int times=0;
int i=0, j=0;
int ptr1=0;
Label:
for(i=0; i<26; i++) {
string[len-1] = 'a' + i;
printf("%s\n", string);
}
strrev(string);
ptr1=0;
while(string[ptr1]=='z') ptr1++;
if(ptr1!=len) {
for(j=0; j<ptr1; j++) string[j]='a';
string[ptr1]++;
strrev(string);
goto Label;
}
}
// ====================================
// main function
int main(int argc, char **argv)
{
memset(end_string, 200, 'z');
for(int i=1; i<=5; i++) directory(i);
return 0;
}
--
做任何事就像投籃
不去試 永遠不知道會不會進
投了就算不進也沒關係
因為你已經試過了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.68.127.69
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章