forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC_simulation_n.cpp
50 lines (44 loc) · 1.14 KB
/
AC_simulation_n.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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n.cpp
* Create Date: 2014-12-20 10:43:06
* Descripton: simulation
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
private:
// get number from ver[pos] into num
void getNum(const string &version, int &len, int &pos, int &num) {
num = 0;
while (pos < len && version[pos] != '.') {
num = num * 10 + version[pos] - '0';
pos++;
}
pos++;
}
public:
int compareVersion(string version1, string version2) {
int len1 = version1.length();
int len2 = version2.length();
int curPos1 = 0, curPos2 = 0;
int num1, num2;
while (curPos1 < len1 || curPos2 < len2) {
getNum(version1, len1, curPos1, num1);
getNum(version2, len2, curPos2, num2);
if (num1 > num2)
return 1;
if (num1 < num2)
return -1;
}
return 0;
}
};
int main() {
string a, b;
Solution s;
while (cin >> a >> b)
cout << s.compareVersion(a, b) << endl;
return 0;
}