Programming 版 (精华区)

发信人: SwordLea (飞刀李), 信区: Programming
标  题: [程序大战]20040720之攻擂程序(hitool)
发信站: 哈工大紫丁香 (Thu Aug  5 09:13:45 2004), 转信

    测试结果:572ms  
    测试结果:307457 项

void StrFilter(LPBYTE pBuffer, DWORD dwFileSize, int nLen, CString &sResult, DWORD *pdwElapsedTime)
{
        // 计时开始
        CLocalCalculagraph cc;
        cc.Start();

        std::vector<Filter> vFilter;
        DWORD dwID = 0;
        int len = 0;
        int len1=0;
        
        for (DWORD i = nLen-1; i < dwFileSize;)
        {
                
                // 2004-7-23 9:57 最短长度处字符判断
                BYTE ch = *(pBuffer + i);
                if (!(ch >= 32 && ch <= 126)) 
                {
                        i += nLen;
                        continue;
                }
                
                len=1;
                ch = *(pBuffer + i-len );
                for(; ch >= 32 && ch <= 126; )
                        ch = *(pBuffer + i -(++len));
                
                ch = *(pBuffer + i+1 );
                for(len1=1; ch >= 32 && ch <= 126; )
                        ch = *(pBuffer + i +(++len1));
                
                len+=len1-1;
                if (len >=nLen)
                {
                        // 长度合格
                        Filter f;
                        f.dwID = dwID ++;
                        f.dwOffset = i-(len-len1) ;
                        f.lpString = new char[len+1];
                        if (!f.lpString ) return ;
                        strncpy(f.lpString , (LPCTSTR)pBuffer + i-(len-len1), len);
                        f.lpString[len] = 0;
                        f.nLength = len;
                        vFilter.push_back(f);
                }
                i+=len1+nLen;
        }

        // 计时停止
        cc.Stop();
        *pdwElapsedTime = cc.GetElapsedTime() ;

        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));
                
                delete(p->lpString);
        }
        vBuffer.push_back(0);
        sResult = &vBuffer[0]; 
}
--
    I came, I saw, I conquered ! — Caesar


※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.246.*]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:5.846毫秒