Reverse a sentence
来源:互联网 发布:淘宝直通车品牌资质 编辑:程序博客网 时间:2024/04/28 03:39
#include <iostream>using namespace std;char sentence[] = "i like this program";//1.reverse all chars//2.rever only words.void revese_char(char* _string) {char* start = _string;char* end = start;while (*end) { ++end; }--end;while (start < end){char tmp = *start;*start = *end;*end = tmp;++start;--end;}}//----------------------------------------------inline void reverse_from_to(char* start, char* end) {while (start < end){char tmp = *start;*start = *end;*end = tmp;++start;--end;}}void reverse_words(char* _string) {revese_char(_string);cout<<"reversed chars::"<<sentence<<'\n';char* start = _string;char* end = start;while (*end != '\0') {if (*end == ' ') {char* pos = end - 1;reverse_from_to(start, pos);++end;start = end;}else {++end;}}}//-----------------------------------------------int main(){reverse_words(sentence);cout << sentence;cin.get(); return 0;}
0 0
- Reverse a sentence
- Reverse a string and reverse a sentence
- reverse words in a sentence
- No. 07 - Reverse words in a sentence
- Reverse the words in a sentence in place
- A sentence every day
- a sentence every day!
- a sentence every day!
- Title Case a Sentence
- A sentence for a day
- Given an array of characters which form a sentence of words, give an efficient algorithm to reverse
- A hundred classical english sentence
- A. Whose sentence is it?
- sentence
- Sentence
- Find a useful sentence in YzLib
- codeforces 312A.Whose sentence is it?
- Sentence Created by fortune(a command)
- JAVA SE8 OCA/OCP和PL/SQL OCA/OCP认证书籍推荐
- 热血江湖-术语整理
- dom4j解析xml
- Logger Rate Limiter
- 第43课:Spark Streaming中UI内幕实现彻底解密
- Reverse a sentence
- Java中Map和Vector集合
- HDU2614 Beat
- 改变 记事本 notepad.exe 默认编码模式
- Android第一周(第一部分)
- java 对象序列化 与 静态变量 及 transient
- 第二章:简单的Java程序
- Backup Volume 操作 - 每天5分钟玩转 OpenStack(59)
- 和成熟男人谈恋爱是什么感觉