hihocoder #1082 : 然而沼跃鱼早就看穿了一切
2016-08-26 15:20
357 查看
题目连接:http://hihocoder.com/problemset/problem/1082?sid=860611
此题利用了c++标准模板库的算法
此题利用了c++标准模板库的算法
s.find(string)找到string 的位置
s.replace(pos,n,p)将pos后的n个字符用p代替。
string::npos是一个常数
#include <string> #include <stdio.h> #include <iostream> using namespace std; int main() { string str; string t = "marshtomp"; string s = "fjxmlhx"; while (getline(cin, str, '\n')) { string lowstr = str; for (int i = 0; i < str.length(); ++i) //转换成小写 lowstr[i] = tolower(str[i]); while (lowstr.find(t) != string::npos) //查找是否存在t字符床 { int pos = lowstr.find(t); //查找指定的字符串,返回位置 str.replace(pos, t.size(), s); //从位置pos开始的n个字符串替换成s lowstr.replace(pos, t.size(), s); } cout << str << endl; } }
相关文章推荐
- hihoCoder #1082 : 然而沼跃鱼早就看穿了一切(字符串处理)
- Hihocoder #1082 : 然而沼跃鱼早就看穿了一切 暴力
- hihocoder #1082 : 然而沼跃鱼早就看穿了一切
- hihoCoder:#1082 然而沼跃鱼早就看穿了一切
- hihoCoder 1082然而沼跃鱼早就看穿了一切 (字符串处理)
- hiho 1082 : 然而沼跃鱼早就看穿了一切
- hihoCoder - 1082 - 然而沼跃鱼早就看穿了一切(字符串处理)
- #1082 : 然而沼跃鱼早就看穿了一切
- hihocoder编程练习:#1082 : 然而沼跃鱼早就看穿了一切
- #1082 : 然而沼跃鱼早就看穿了一切(AC版)
- [HIHO1082]然而沼跃鱼早就看穿了一切(字符串水题)
- hihoCoder 1082 : 然而沼跃鱼早就看穿了一切
- hihoCoder#1082 : 然而沼跃鱼早就看穿了一切(做题总结)
- #1082 : 然而沼跃鱼早就看穿了一切
- hihocoder 1082 然而沼跃鱼早就看穿了一切 (替换指定的串 )
- hihoCoder#1082 然而沼跃鱼早就看穿了一切
- HihoCoder#1082: 然而沼跃鱼早就看穿了一切
- 【hihoCoder】1082: 然而沼跃鱼早就看穿了一切
- HihoCoder#1082: 然而沼跃鱼早就看穿了一切
- hihocoder-#1082 : 然而沼跃鱼早就看穿了一切