Korotkodul

string_comparison

Apr 19th, 2025 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <algorithm>
  5. #include <sstream>
  6. using namespace std;
  7. bool cmp(istringstream &s) {
  8. vector<string> a;
  9. string word;
  10. while (s >> word) {
  11. a.push_back(word);
  12. }
  13. if (a.empty()) {
  14. cout << "Yes\n";
  15. exit(0);
  16. }
  17. int n = a.size();
  18. if (n % 2 != 0) {
  19. return false;
  20. }
  21. for (int i = 0; i < n/2; ++i) {
  22. if (a[i] != a[n/2 + i]) {
  23. return false;
  24. }
  25. }
  26. return true;
  27. }
  28. int main() {
  29. string line;
  30. while (getline(cin, line)) {
  31. istringstream s(line);
  32. if (!cmp(s)) {
  33. cout << "No\n";
  34. exit(0);
  35. }
  36. }
  37. return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment