-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompareVersionLatest.cpp
76 lines (38 loc) · 1.37 KB
/
CompareVersionLatest.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
using namespace std;
int ver(string m, string n)
{
string s1;
string s2;
for(int i = 0, j = 0; (i < m.length() || j < n.length()); i++, j++ )
{
if(i >= m.length()) s1 = "0";
else s1 = "";
while(m[i] != '.' && i < m.length())
{
s1 += m[i];
i++;
}
if(i >= m.length()) s2 = "0";
else s2 = "";
while(n[j] != '.' && j < n.length() )
{
s2 += n[j];
j++;
}
double ss1 = stod(s1);
double ss2 = stod(s2);
if(ss1 < ss2 ) return -1;
else if (ss1 > ss2) return 1;
}
return 0;
}
int main()
{
// string m = "1.0.1";
// string n = "1.0.1.1";
string s1 = "19.8.3.17.5.01.0.0.4.0.0.0.0.0.0.0.0.0.0.0.0.0.00.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.000000.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0000000";
string s2 = "19.1.8.3.17.5.01.0.0.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0000.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.000000";
cout << ver(s1,s2) << endl;
return 0;
}