#include "stdafx.h"
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
cout << "輸入一個詞: ";
string word;
cin >> word;
char temp;
int i;
int j=0;
for (i = word.size()-1 ;j < i; --i)
{
for (j = 0; j < i; ++j)
{
temp = word[i];
word[i] = word[j];
word[j] = temp;
}
}
cout << word << "\nDone\n";
return 0;
}
這個運行結果是
輸入一個詞:12345
51234
Done
...............
我想讓他變成
輸入一個詞:12345
54321
Done
...............
我這個程序該怎麼改呀
for (i=word.size()-1,i>word.size()/2;i--)
{
temp=word[i];
word[i]=word[word.size()-1-i];
word[word.size()-1-i]=temp;
}