Advertisement
kolioi

22. Equal Strings C++

Dec 2nd, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. bool AreEqual(const std::string&, const std::string&);
  5.  
  6. int main()
  7. {
  8.  
  9.     std::string s1, s2;
  10.     std::cin >> s1 >> s2;
  11.  
  12.     if (AreEqual(s1, s2))
  13.         std::cout << "Equal\n";
  14.     else
  15.         std::cout << "Not Equal\n";
  16.  
  17.     return 0;
  18. }
  19.  
  20. bool AreEqual(const std::string& a, const std::string& b)
  21. {
  22.     if (a.length() != b.length())
  23.         return false;
  24.    
  25.     for (int i = 0; i < a.size(); ++i)
  26.         if (a[i] != b[i])
  27.             return false;
  28.  
  29.     return true;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement