-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path165.cpp
More file actions
36 lines (33 loc) · 779 Bytes
/
165.cpp
File metadata and controls
36 lines (33 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
class Solution {
public:
int compareVersion(string version1, string version2) {
while(!version1.empty()||!version2.empty())
{
int ver1=version1.empty()?0:stoi(version1);
int ver2=version2.empty()?0:stoi(version2);
if(ver1>ver2)
return 1;
else if(ver1<ver2)
return -1;
else {
int pos1=version1.find('.');
int pos2=version2.find('.');
//pos1 == string::npos意思是没有.
//string::npos是string 的结束位子
version1=(pos1 == string::npos)?"":version1.substr(pos1+1);
version2=(pos2==string::npos)?"":version2.substr(pos2+1);
}
}
return 0;
}
};