字符串替换 hihoCoder1082 然而沼跃鱼早就看穿了一切
2015-08-13 22:41
309 查看
一直因为C++里面没有现成的替换函数而烦恼,只怪自己太懒懒的写
借这题写好这个函数,,以后直接用就好了
借这题写好这个函数,,以后直接用就好了
#include<map> #include<set> #include<cmath> #include<stack> #include<queue> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<iostream> #include<algorithm> #include<functional> using namespace std; const int MX = 1e3 + 5; string Replace(string s, string a, string b, bool Match = false) { string tmp = s; if(!Match) { transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); transform(a.begin(), a.end(), a.begin(), ::tolower); } int pos; while(true) { if((pos = tmp.find(a)) != -1) { tmp.replace(pos, a.length(), b); s.replace(pos, a.length(), b); } else break; } return s; } char S[MX], a[MX] = "marshtomp", b[MX] = "fjxmlhx"; int main() { while(gets(S)) { printf("%s\n", Replace(string(S), string(a), string(b)).c_str()); } return 0; }
相关文章推荐
- poj 2029 Get Many Persimmon Trees
- 虚函数的使用
- JAVA大整数[小结]
- 1、为什么每个viewDidLoad方法中都要使用[super viewDidLoad] ?
- JackSon 数据之间的转换 java
- 随笔
- 什么是 Event Loop
- [拓展]杭电1003(最大子数组问题)
- P命名空间给Bean属性注值
- java执行命令行
- common lisp 中宏定义时不能使用#'? 形式的函数作为参数
- zoj_1002
- Discuz论坛 创始人/超级管理员密码忘记解决办法!
- 【MySql】使用记录<七>
- HDU 5389 Zero Escape (MUT#8 dp优化)
- justfun
- 华为训练题:高级——火车进站(栈与队列,递归)
- C++调用Lua的性能测试
- 3.建造者模式(设计模式笔记)
- Innodb/MyISAM在自增/UUID主键下的性能与索引空间比较