class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 比较版本号
     * @param version1 string字符串 
     * @param version2 string字符串 
     * @return int整型
     */
    int compare(string version1, string version2) {
        // write code here
        int num=0,i,j;
        int len1=version1.length(),len2=version2.length();
        for(i=0;i<len1;i++)
        {
            if(version1[i]=='.') num++;
        }
        for(i=0;i<len2;i++)
        {
            if(version2[i]=='.') j++;
        }
        if(j>num) num=j;
        int t1,t2;
        i=0,j=0;
        int k=0;
        while(i<len1 && j<len2 || k<=num)
        {
            t1=0,t2=0;
            while(version1[i]!='.'&&i<len1)
            {
                t1*=10;
                t1+=version1[i]-'0';
                i++;
            }
            while(version2[j]!='.'&&j<len2)
            {
                t2*=10;
                t2+=version2[j]-'0';
                j++;
            }      
            if(t1>t2) 
            {
                return 1;
            }
            else if(t1<t2)
            {
                return -1;
            }
            else{
                i++;
                j++;
                k++;
            }
        }
        return 0;
    }
};