class Solution {
public:
    vector<string> handle(string version){
        vector<string> res;
        string str;
        int n = version.length();
        for(char ch:version){
            if(ch == '.'){
                while(str.length() > 1 && str[0] == '0') str.erase(0, 1);
                res.push_back(str);
                str = "";
            }else str += ch;
        }
        while(str.length() > 1 && str[0] == '0') str.erase(0, 1);
        res.push_back(str);
        return res;
    }
    int cmp(string a, string b){
        int m = a.length(), n = b.length();
        if(m > n) return 1;
        else if(m < n) return -1;
        for(int i = 0; i < n; i ++){
            if(a[i] > b[i]) return 1;
            else if(a[i] < b[i]) return -1;
        }
        return 0;
    }
    int compare(string version1, string version2) {
        // write code here
        vector<string> a = handle(version1);
        vector<string> b = handle(version2);
        int m = a.size(), n = b.size();
        int maxn = max(m, n);
        for(int i = m; i < maxn; i ++) a.push_back("0");
        for(int i = n; i < maxn; i ++) b.push_back("0");
        for(int i = 0; i < maxn; i ++){
            int c = cmp(a[i], b[i]);
            if(c != 0) return c;
        }
        return 0;
    }
};