#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
string s;
while (n--&&cin >> s)
{
string s1;
s1.assign(s.rbegin(), s.rend());
if (s1 == s)
cout << "yes" << endl;
else cout << "no" << endl;
}
}
return 0;
}
第一程序用的反向迭代器+assign操作,反转到别的string里
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
string s;
while (n--&&cin >> s)
{
string s1;
s1 = s;
reverse(s1.begin(),s1.end());
if (s1 == s)
cout << "yes" << endl;
else cout << "no" << endl;
}
}
return 0;
}
第二个程序用的reverse操作,原地反转