Advertisement
Glenpl

compare strings

Mar 7th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. string bigger(string a, string b)
  2. {
  3.     if(a == b) return a;
  4.     if(a.length() != b.length())
  5.         return ((a.length() > b.length()) ? (a) : (b));
  6.     int i = 0;
  7.     while(a[i] == b[i])
  8.         i++;
  9.     return ((a[i] > b[i]) ? (a) : (b));
  10. }
  11.  
  12. bool compare(string a, string comp, string b)
  13. {
  14.     if(comp == "==" || comp == ">=" || comp == "<=")
  15.         if(a == b) return true;
  16.     if(comp == "==") return false;
  17.     if(comp == "!=") return true;
  18.     string bigger_num = bigger(a, b);
  19.     if((comp == ">" || comp == ">=") && bigger_num == a) return true;
  20.     if((comp == "<" || comp == "<=") && bigger_num == b) return true;
  21.     return false;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement