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;
        
    }
  • 相关阅读:
    Redis (error) NOAUTH Authentication required.问题
    C# File() 方法 contentType参数取值
    Java常用快捷键汇总(杂乱无章,持续更新)
    VUE项目发布至IIS(不涉及代理)
    js的休眠实现---sleep()
    Oracle 分页
    winform Panel设定 按钮显示位置
    Chart控件绘制实时折线图表——Spline
    .NET打包合并dll方法
    ComboBox绑定键值对
  • 原文地址:https://www.cnblogs.com/finallyliuyu/p/1985685.html
Copyright © 2011-2022 走看看