poj_3650 字符串处理
来源:互联网 发布:淘宝个人转企业店铺 编辑:程序博客网 时间:2024/05/05 01:18
使用<string>中字符串处理函数:
(1)、getline(istream &in,string &s):
–从输入流中读入字符,存到string变量
–直到出现以下情况为止:
•读入了文件结束标志
•读到一个新行
•达到字符串的最大长度
(2)、int position=string.find("xxx"):
返回string中首次出现串xxx的下标位置给position
如果position == s.npos ,说明没有找到,C++用一个特别的标志npos标识;
其它用法:
int position=string.find("xxx",5);
从string的下标5后开始查找;
(3)、string.replace(position,len,"xxx");
将串stringpos开始的位置,len长度的串由串xxx替代;
code:
<span style="font-size:18px;">#include <iostream>#include <string>#include <fstream>using namespace std;string replace[7][2] = {{ "%", "%25" },{ " ", "%20" },{ "!", "%21" },{ "$", "%24" },{ "(", "%28" },{ ")", "%29" },{ "*", "%2a" }};int main(){//fstream in("input.txt");string s;while (getline(cin,s) && s!="#"){for (int i = 0; i < 7; i++){int pos = s.find(replace[i][0]);while (pos != string::npos){s.replace(pos,1,replace[i][1]);pos += 2;pos = s.find(replace[i][0],pos);}}cout << s << endl;}//system("pause");return 0;}</span>
0 0
- poj_3650 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 处理字符串
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 字符串处理
- 电风扇与铅笔
- UIWebView 更改加载内容里面的字体大小
- 例题8-5 Gergovia的酒交易 UVa11054
- OpenGL的矩阵堆栈
- QT串口编程的相关类2(QSerialPort)
- poj_3650 字符串处理
- tabbar和navigation的结合(跳转)
- 公告:本人的新博客地址:http://hujiandong.com,希望以后继续坚持写blog。
- 自学成才!16个非常优秀的在线教育网站
- 注释转换(c++注释到C注释)
- 进制颜色值转换到RGB值(cocos2d-iPhone版)
- MFC中异形分层窗口设计
- 切割字符串
- Androguard的使用方法