【发布时间】:2015-05-02 06:02:05
【问题描述】:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
string buildRWord(string word) {
string rword = "";
vector<string> wrd;
for(int i = 0; i < word.length(); ++i)
wrd.push_back(word.substr(i,1));
reverse(word.begin(), word.end());
for(int i = 0; i < word.size(); ++i)
rword += word[i];
return rword;
}
int main()
{
string aword;
cout << "Enter a word: ";
cin >> aword;
string raword = buildRWord(aword);
if (raword == aword)
cout << aword << " is a palindrome."
<< endl;
else
cout << aword << " is not a palindrome."
<< endl;
return 0;
}
这个程序完美运行,但我不知道它是如何工作的,我的意思是内部逐步操作。有人可以解释这段代码吗?我需要关于全局函数部分的详细解释。
【问题讨论】:
标签: string vector data-structures stl