class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 比较版本号
* @param version1 string字符串
* @param version2 string字符串
* @return int整型
*/
vector<string> split(string s, char op) {
int n = s.size();
vector<string> res;
for(int i = 0; i < n; i++) {
string ans = "";
while(s[i] != op && i < n) {
ans += s[i];
i++;
}
res.push_back(ans);
}
return res;
}
int compare(string version1, string version2) {
// write code here
vector<string> s1 = split(version1, '.');
vector<string> s2 = split(version2, '.');
int l1 = s1.size();
int l2 = s2.size();
for(int i = 0; i < l1 && i < l2; i++) {
long long num1 = 0;
long long num2 = 0;
for(int j = 0; j < s1[i].size(); j++) {
num1 += num1 * 10 + s1[i][j] - '0';
}
for(int j = 0; j < s2[i].size(); j++) {
num2 += num2 * 10 + s2[i][j] - '0';
}
if(num1 > num2)
return 1;
else if( num1 < num2)
return -1;
}
if(l1 > l2) {
for(int i = l2; i < l1; i++) {
int num = 0;
for(int j = 0; j < s1[i].size(); j ++)
num += num * 10 + s1[i][j] - '0';
if( num > 0 )
return 1;
else if(num < 0)
return -1;
}
return 0;
}
else if( l1 < l2) {
for(int i = l1; i < l2; i++) {
int num = 0;
for(int j = 0; j < s2[i].size(); j ++)
num += num * 10 + s2[i][j] - '0';
if( num > 0 )
return -1;
else if(num < 0)
return 1;
}
return 0;
}
else
return 0;
}
};