Advertisement
Glenpl

return bigger string value

Mar 7th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string bigger(string, string);
  5.  
  6. int main()
  7. {
  8.     cout << bigger("9995", "9996") << endl;
  9.     return 0;
  10. }
  11.  
  12. string bigger(string a, string b)
  13. {
  14.     if(a == b) return a;
  15.     if(a.length() != b.length())
  16.         return ((a.length() > b.length()) ? (a) : (b));
  17.     int i = 0;
  18.     while(a[i] == b[i])
  19.         i++;
  20.     return ((a[i] > b[i]) ? (a) : (b));
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement