(1)
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<stdlib.h>
using namespace std;
int main()
{
string str;
cout<<"please enter a string"<<endl;
getline(cin,str);
cout << endl;
string word;
istringstream to_word(str);
vector<string> vstr;
while(to_word>>word)
{
vstr.push_back(word);
}
for(vector<string>::reverse_iterator iter = vstr.rbegin(); iter!= vstr.rend(); iter++)
{
cout << *iter << " ";
}
system("pause");
return 0;
}
(2)
#include<iostream>
#include<stdlib.h>
using namespace std;
void _reverse(char *s, int from, int to)
{
while(from < to)
{
char t = s[from];
s[from++] = s[to];
s[to--] = t;
}
}
void reverse1(char *s, int m, int n)
{
m = m%n;
_reverse(s,0,m-1);
_reverse(s,m,n-1);
_reverse(s,0,n-1);
}
int main()
{
char s[6] = "hello";
reverse1(s,3,5);
for(int i = 0; i<6; i++)
{
cout<< s[i];
}
cout<< endl;
system("pause");
return 0;
}