• 软件版本号比较(字符串比较)


    7.版本号比较(字符串比较)

    复制代码
    int CompareVersion(QString strVer1, QString strVer2)
    {
        if ( !strVer1.compare( strVer2 ) )
        {
            return 0;
        }
    
        QStringList list1 = strVer1.split( "." );
        QStringList list2 = strVer2.split( "." );
    
        int iTotal1 = list1.count();
        int iTotal2 = list2.count();
    
        int iTotal=iTotal1>iTotal2?iTotal2:iTotal1;
    
        int iValue1 = 0, iValue2 = 0;
        bool ibOK1 = false, ibOK2 = false;
        for ( int iNum = 0; iNum < iTotal; ++iNum )
        {
            iValue1 = list1[iNum].toInt( &ibOK1 );
            if (!ibOK1)
            {
                iValue1=0;
            }
    
            iValue2 = list2[iNum].toInt( &ibOK2 );
            if (!ibOK2)
            {
                iValue2=0;
            }
    
            if (iValue1==iValue2)
            {
                continue;
            }
            else if ( iValue1 < iValue2 )
            {
                return -1;
            }
            else
            {
                return 1;
            }
        }
    
        return iTotal1<iTotal2?-1:1;
    }
    复制代码

    测试:

    CompareVersion("16.01.19", "16.01.19") //return 0;
    CompareVersion("16.01.19", "16.01.18") //return 1;
    CompareVersion("16.01.18", "16.01.19") //return -1;

    https://www.cnblogs.com/sz-leez/p/6537004.html

  • 相关阅读:
    Luogu P1596 [USACO10OCT]湖计数Lake Counting
    Luogu P1757 通天之分组背包
    数据建模笔记1
    单纯形算法 matlab
    有效集 matlab代码
    拟牛顿 DFP matlab
    FR共轭梯度法 matlab
    整数规划
    线性规划 Matlab
    远期、期货和互换(三)
  • 原文地址:https://www.cnblogs.com/findumars/p/9189641.html
Copyright © 2020-2023  润新知