问题:如何实现student a am i转换成为i am a student?
解析:可将语句完全倒置,成为i ma a tneduts,再将逐个单词倒置,成为i am a student
#include
#include
void reverse_string(char *l, char *r)
{
while (l < r)
{
char tmp = *l;
*l =...
分类:
其他好文 时间:
2015-05-10 19:03:01
阅读次数:
125
方式一:将字符串反向输出来,不改变内存(递归实现)
void reverse_string(char *str)
{
/*遇到'\0'什么也不做,函数结束*/
if(*str == '\0')
;
else
{
/*输出下一个*/
reverse_string(str + 1);
cout<<*str;
}
}方式二:改变内存(交换法)
/*非递归实现:操作内存*/...
分类:
其他好文 时间:
2015-05-10 18:58:07
阅读次数:
177
https://leetcode.com/problems/reverse-words-in-a-string/Given an input string, reverse the string word by word.For example,Given s = "the sky is blue"...
分类:
其他好文 时间:
2015-05-07 20:19:27
阅读次数:
106
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C prog...
分类:
其他好文 时间:
2015-05-06 01:07:01
阅读次数:
123
Given an input string, reverse the string word by word.For example,
Given s = “the sky is blue”,
return “blue is sky the”.Update (2015-02-12):
For C programmers: Try to solve it in-place in O(1) s...
分类:
其他好文 时间:
2015-05-06 00:01:27
阅读次数:
188
问题Reverse Words in a String
Given an input string, reverse the string word by word.For example,
Given s = "the sky is blue",
return "blue is sky the".
Update (2015-02-12):
For C programmers: Tr...
分类:
其他好文 时间:
2015-05-05 12:41:25
阅读次数:
128
string Reverse(string s){ int len=s.size(); string ts(len,' ');//一定得初始化 int j=0; for(int i=len-1;i>=0;i--) ts[j++]=s[i]; return ts;}
分类:
其他好文 时间:
2015-04-28 13:39:17
阅读次数:
99
问题:翻转字符串中的单词顺序,如“hello world”变成“world hello”。要求使用常量空间。
c++代码如下:
void reverse(string &s, int start, int end){
int len=end+start;
int center=len/2;
for(int i=start;i<center;i++){
...
分类:
其他好文 时间:
2015-04-25 21:13:09
阅读次数:
127
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".For C programmers: Try to solv...
分类:
其他好文 时间:
2015-04-17 18:05:36
阅读次数:
108
Given an input string, reverse the string word by word.For example, Given s = "the sky is blue", return "blue is sky the".Update (2015-02-12): For C p...
分类:
其他好文 时间:
2015-04-17 09:41:26
阅读次数:
116