zoukankan      html  css  js  c++  java
  • LCS算法示例的主函数调用

    作者finallyly 出处 博客园(转载请注明作者和出处)

    main.cpp
    #include "stdafx.h"
    #include 
    "stringprocess.h"
    #include 
    <iostream>
    #include 
    "windows.h"
    using namespace std;
    wstring String2Wstring(
    string sResult)
    {
        
    int iWLen=MultiByteToWideChar( CP_ACP, 0, sResult.c_str(), sResult.size(), 00 );// 计算转换后宽字符串的长度。(不包含字符串结束符)  

        wchar_t 
    *lpwsz= new wchar_t [iWLen+1];  


        MultiByteToWideChar( CP_ACP, 
    0, sResult.c_str(), sResult.size(), lpwsz, iWLen ); // 正式转换。  

        lpwsz[iWLen] 
    = L'\0';   

        wstring wsResult(lpwsz);  

        delete []lpwsz;  

        
    return wsResult;  
        
    }

    string Wstring2String(wstring wsResult)
    {
        
    string sResult;  
        
    int iLen= WideCharToMultiByte( CP_ACP, NULL, wsResult.c_str(), -1, NULL, 0, NULL, FALSE ); // 计算转换后字符串的长度。(包含字符串结束符)  
        char *lpsz= new char[iLen];  
        WideCharToMultiByte( CP_OEMCP, NULL, wsResult.c_str(), 
    -1, lpsz, iLen, NULL, FALSE); // 正式转换。  
        sResult.assign( lpsz, iLen-1 ); // 对string对象进行赋值。  
        delete []lpsz;  
        
    return sResult;

    }

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

        

        
        wstring wstr1
    =L"生命无国界,我们不应该庆祝日本地震";
        wstring wstr2
    =L"我们的生命无国界,因此不应该庆祝日本地震";
        
    string str1=Wstring2String(wstr1);
        
    string str2=Wstring2String(wstr2);
        cout
    <<"待对比的字符串为:"<<endl;
        cout
    <<"x串: "<<str1.c_str()<<endl;
        cout
    <<"y串: "<<str2.c_str()<<endl;
        
    const wchar_t *xpart=wstr1.c_str();
        
    const wchar_t *ypart=wstr2.c_str();
        stringprocess p;
        
    int len=p.CalculateLongestCommonSequenceLen(xpart,ypart);
        
    if (len>0)
        {
            wstring wlcsequence
    =p.GetLongestCommonSequence();
            
    string lcsequence=Wstring2String(wlcsequence);
            cout
    <<"最大公共字串为:"<<lcsequence.c_str()<<endl;
            
    int*xpartinfo=new int[wlcsequence.size()];
            
    int *ypartinfo=new int[wlcsequence.size()];
            p.GetIndexesInfo(xpartinfo,ypartinfo);
            cout
    <<"最大公共字串在x字符串中的位置:"<<endl;
            
    for (int i=0;i<wlcsequence.size();i++)
            {
                cout
    <<xpartinfo[i]<<";";
            }
            cout
    <<endl;
            cout
    <<"最大公共字串在y字符串中的位置:"<<endl;
            
    for (int i=0;i<wlcsequence.size();i++)
            {
                cout
    <<ypartinfo[i]<<";";
            }cout
    <<endl;

            delete xpartinfo;
            delete ypartinfo;

        }
        cout
    <<len<<endl;

        
        cout
    <<"finish"<<endl;
        
    int f;
        cin
    >>f;
        
    }
  • 相关阅读:
    试玩mpvue,用vue的开发模式开发微信小程序
    laravel 整合 swoole ,并简单 ab 测试对比性能以及在 PHPstorm 中利用debug调试配置swoole服务中的PHP代码
    移动端固定头部和固定左边第一列的实现方案(Vue中实现demo)
    PhpStorm 2017.3 版本在 Mac 系统 macOS High Sierra 版本 10.13.3 中运行很卡顿
    xdebug : Debug session was finished without being paused
    SVN checkout 出的项目在PHPstorm中打开没有subversion(SVN)选项按钮怎么办?
    PHP应用的CI/CD流程实践与学习:一、PHP运行环境的准备
    Mac环境下PHPstorm配置xdebug开发调试web程序
    『备忘录』elasticsearch 去重分页查询
    Mac下docker搭建lnmp环境 + redis + elasticsearch
  • 原文地址:https://www.cnblogs.com/finallyliuyu/p/1985685.html
Copyright © 2011-2022 走看看