The problem requires checking if the second string 'tWord' is the reverse of the first
string
'sWord'. To solve this, we
reverse 'sWord'
and
compare it with 'tWord'
.
If
they
match
, we output
"YES"
; otherwise, we
output
"NO"
. This
approach ensures that we correctly determine if 'tWord' is the reverse of 'sWord'.
#include <bits/stdc++.h> using namespace std; int main(){ string sWord,tWord; cin >> sWord >> tWord; reverse(sWord.begin(),sWord.end()); if(tWord == sWord) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
The algorithm reverses the string and compares it, both of which take linear time relative to the length of the string.
The algorithm uses a constant amount of extra space, regardless of the input size.