Programming 版 (精华区)
发信人: SwordLea (飞刀李), 信区: Programming
标 题: [程序大战]20040720 第1小板凳
发信站: 哈工大紫丁香 (Wed Jul 21 19:03:33 2004), 转信
// 测试结果:
2003-11-10 14:36 62,073,445 MinGWStudioFullSetupPlus-2.02.exe
Used time: 27851ms (平均值)
硬件配置:Toshiba 笔记本 P4 1.5G(Centrino) / 1G
操作系统:Win XP(CN)
编译器: VC++6.0
编译版本:Release
#include <vector>
typedef struct _Filter
{
DWORD dwID; // 该字符串出现序号(由0开始)
DWORD dwOffset; // 在文件中偏移
short nLength; // 该字符串长度
char* lpString; // 该字符串内容
}Filter,*PFilter;
void StrFilter(LPBYTE pBuffer, DWORD dwFileSize, int nLen, CString &sResult)
{
std::vector<Filter> vFilter;
DWORD dwID = 0;
int len = 0;
for (DWORD i = 0; i < dwFileSize; i ++)
{
BYTE ch = *(pBuffer + i);
for(int len = 0; ch >= 32 && ch <= 126; len ++)
ch = *(pBuffer + i + len);
if (len > nLen)
{
// 长度合格
Filter f;
f.dwID = dwID ++;
f.dwOffset = i ;
f.lpString = new char[len+1];
if (!f.lpString ) return ;
strncpy(f.lpString , (LPCTSTR)pBuffer + i, --len);
f.lpString[len] = 0;
f.nLength = len;
vFilter.push_back(f);
i += len;
}
}
std::vector<char> vBuffer;
for (PFilter p = vFilter.begin(); p != vFilter.end(); p ++)
{
CString sBuf;
sBuf.Format("%u: Offset:%u Length:%d\t%s\r\n",
p->dwID, p->dwOffset, p->nLength,p->lpString);
for ( int j = 0; j < sBuf.GetLength(); j ++)
vBuffer.push_back(sBuf.GetAt(j));
//sResult += szBuf; // 这将是一场恶梦!!!
delete(p->lpString);
}
vBuffer.push_back(0);
sResult = &vBuffer[0];
}
void CTest1Dlg::OnOK()
{
CRichEditCtrl *pRiched = &m_ctrlRichEd;
CLocalCalculagraph cc;
CFile f;
if (!f.Open("d:\\tmp\\MinGWStudioFullSetupPlus-2.02.exe",CFile::modeRead))
return;
DWORD dwSize = f.GetLength();
LPBYTE pBuffer = new BYTE[dwSize + 1];
f.Read(pBuffer ,dwSize );
f.Close();
cc.Start();
CString sResult;
StrFilter(pBuffer , dwSize, 5, sResult);
cc.Stop();
pRiched->SetWindowText(sResult);
delete pBuffer ;
// 以下是用于评测的结果
CString sMsg;
sMsg.Format("Used time:%ulms", cc.GetElapsedTime() );
AfxMessageBox(sMsg);
}
--
I came, I saw, I conquered ! — Caesar
※ 修改:·SwordLea 于 Jul 22 14:14:03 修改本文·[FROM: 202.118.246.241]
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.246.241]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.540毫秒