本网页所有文字内容由 imapbox邮箱云存储,邮箱网盘, iurlBox网页地址收藏管理器 下载并得到。
ImapBox 邮箱网盘 工具地址: https://www.imapbox.com/download/ImapBox.5.5.1_Build20141205_CHS_Bit32.exe
PC6下载站地址:PC6下载站分流下载
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox 网页视频 工具地址: https://www.imapbox.com/download/ImovieBox4.7.0_Build20141115_CHS.exe
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
 
 
 
 
 题目地址:https://oj.leetcode.com/problems/compare-version-numbers/   题目描述:  
  Compare two version numbers version1 and version1.  You may assume that the version strings are non-empty and contain only digits and the   Here is an example of version numbers ordering:  0.1 < 1.1 < 1.2 < 13.37  看到这道题目的AC率那么低也就尝试着做一做。  算法思路:1.首先考虑将两个字符串version1和version2进行切分,因为可能会出现这样的测试用例"1.0.1",有多个点。  2.将按照"."分割之后的数字放到一个容器vector里面或者一个数组里面就行了。  3.然后依次进行比较。有一点需要注意的是,有类似的用例"1.0.0"和"1"其实是相等的,因此,要将容器或者数组中的后缀0去掉,那么比较的时候就没有什么顾虑了。  AC和测试代码:  
  还是根据测试用例进行修改代码,因此考虑到比较完整的测试用例很重要。    
 If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.. character.
 The . character does not represent a decimal point and is used to separate number sequences.
 For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth  second-level revision of the second first-level revision.#include<iostream> #include<string> #include<vector>  using namespace std;  class Solution { private:         vector<int> v1,v2; public:     //split the string by '.'      void split_string(const char *str , vector<int> &v)        {         char *buf = new char[ strlen(str) + 1 ];         strcpy(buf,str);         char *p = strtok(buf,".");         while( p!=NULL )         {             v.push_back( atoi(p) ) ;             p = strtok(NULL,".");         }     }          //compare two version     int compareVersion(string version1, string version2)      {         const char *str1 = version1.c_str();         const char *str2 = version2.c_str();                  split_string(str1,v1);         split_string(str2,v2);                  return judge();     }          int judge()     {         //prune the suffix zero : 1.0 == 1         while( v1.size()!=0 && v1[v1.size()-1]==0 )         {             v1.pop_back();                }          while( v2.size()!=0 && v2[v2.size()-1]==0 )         {             v2.pop_back();                }                  int size = min( v1.size(),v2.size() );         int i;         for(i=0;i<size;i++)         {             if( v1[i]>v2[i] )   return 1;             else if( v1[i]<v2[i] ) return -1;             else continue;         }                  if( v1.size() > v2.size() )              {                return 1;           }         else if( v1.size() < v2.size() ) return -1;         else return 0;              } };  int main() {     Solution s ;     cout<<s.compareVersion("1.0","1")<<endl;          system("pause");     return 0; } 
 
 
阅读和此文章类似的: 程序员专区
 官方软件产品操作指南 (170)
官方软件产品操作指南 (170)