"三步反转"处理字符串
来源:互联网 发布:怎么进入网站的数据库 编辑:程序博客网 时间:2024/05/23 13:00
istringstream、ostringstream、stringstream 类介绍 .
http://www.cnblogs.com/gamesky/archive/2013/01/09/2852356.html
下面的输入处理比较常用:
#include <cstdio>#include <iostream>#include <string>#include <sstream>using namespace std ;int main(){ freopen("in.txt", "r", stdin); string str, line; while(getline(cin, line)) { istringstream stream(line); while(stream>>str) cout<<str.c_str()<<endl; } return 0;}
输入
I am a student.
输出
I
am
a
student.
C++编程中关于输入的一些函数
cin、cin.get()、cin.getline()、getline()、gets()等函数的用法:http://www.cnblogs.com/wanghao111/archive/2009/09/05/1560822.html
c++中string类的详解
http://blog.csdn.net/yzl_rex/article/details/7839379
三步反转
#include <cstdio>#include <iostream>#include <string>#include <sstream>using namespace std ;// 反转字符串string reverse_string(string s){ int len = s.length(); int from = 0 ; int to = len-1; while(from < to) { char tmp = s[from]; s[from] = s[to]; s[to] = tmp; from ++ ; to --; } return s;}int main(){ //freopen("in.txt", "r", stdin); string str, line; while(getline(cin, line)) { string rs = ""; istringstream stream(line); int words_num = 0; while(stream>>str) { if(words_num == 0) rs += reverse_string(str) ; else rs += " " + reverse_string(str); words_num ++ ; } cout << reverse_string(rs) << endl ; } return 0;}
输入1
I am a student.
输出1
student. a am I
输入2
How are you
输出2
you are How
0 0
- "三步反转"处理字符串
- 字符串处理-----字符串反转
- 1.1字符串旋转--左移,右移x位置--三步反转
- 字符串反转处理
- 字符串处理之反转单词
- 逆置字符串之三步翻转
- php反转字符串的三种方法
- 字符串反转的三种方法
- 字符串反转的三种方法
- 三步实现jQuery方式处理事件
- Python字符串处理:按单词反转
- 字符串反转,单词反转
- 字符串反转
- 反转字符串
- 字符串反转
- 字符串反转
- 反转字符串
- 字符串反转
- UVa 401 Palindromes
- 关于C++中sort函数所使用的cmp函数中的&的疑惑
- jsp传参数中文乱码问题url&后台
- POJ-2594-Treasure Exploration(可重点最小路径覆盖)
- C++ new内存分配
- "三步反转"处理字符串
- OS X El Capitan U盘安装
- uva 11419 最大匹配
- 2.5 maven+spring4.X基础上搭建mybatis
- hdoj 1074 Doing Homework 【状压dp】
- Android studio学习笔记
- 弱鸡的笔记整理
- 安装svn插件的多种方式
- 对linux内核学习的一点感受