Easy and readable cpp program


#1

Comment body goes here.int cmp(string &a,string &b){
for(int i=0;i<a.length();i++){
if(a[i]>b[i]) return 1;
if(a[i]<b[i]) return -1;
}
return 0;
}
string rem_zero(string s){
int i=0;
if(s=="") return s;
while(s[i]==‘0’){
s=s.erase(i,1);
}
return s;
}
int help(string a, string b,int i,int j,int m,int n){
if(i>=m && j>=n) return 0;
string aa,bb;
while(i<a.length()&&a[i]!=’.’){
aa+=a[i++];
}
while(j<b.length()&&b[j]!=’.’){
bb+=b[j++];
}
aa=rem_zero(aa);
bb=rem_zero(bb);
if(aa.length()>bb.length()) return 1;
if(aa.length()<bb.length()) return -1;
if(aa.length()==bb.length()){
int z=cmp(aa,bb);
if(z==1) return 1;
if(z==-1) return -1;
return help(a,b,i+1,j+1,m,n);
}
}
int Solution::compareVersion(string a, string b) {
if(a==b) return 0;
return help(a,b,0,0,a.length(),b.length());
}