覺得自己的程序寫的太蠢,求指點。

來源: calboy 2009-10-19 19:48:52 [] [博客] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (844 bytes)
覺得自己的程序寫的太蠢,求指點。
竟然用到了set和遞歸,肯定內存占用很大,
求改進指點。謝謝。

// test102.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
#include
#include

using namespace std;

void DoCombine(set &mystrset, string mystr)
{
if (mystr.length()==0) return;

mystrset.insert(mystr);

for (int i=0; i {
string tmp=mystr;
tmp.erase(i, 1);
DoCombine(mystrset, tmp);
}

}

int _tmain(int argc, _TCHAR* argv[])
{
set mystrset;

DoCombine(mystrset, "abcd");

for (set::iterator it=mystrset.begin(); it!=mystrset.end(); ++it)
cout << *it << endl;

getchar();

return 0;
}
請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”