标签:
首先这里的问题在于如何使用逆转的字符串,这里有很多实现的方法:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string s;
cin>>s;
for (int i = s.size()-1; i >= 0; --i)
{
cout<<s[i];
}
cout<<endl;
return 0;
}
#include <iostream>
#include <string>
#include <algorithm>
- using namespace std;
int main(int argc, char const *argv[])
{
string s;
cin>>s;
reverse(s.begin(),s.end());
cout<<s<<endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string str="sdfghjkl";
string::reverse_iterator rIt = str.rbegin();
while (rIt != str.rend())
{
cout << *rIt;
rIt++;
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string str;
cin>>str;
string::reverse_iterator rIt ;
for (rIt = str.rbegin(); rIt != str.rend(); ++rIt)
{
cout << *rIt;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/clifff/p/5038568.html