Shanshan Pythoner Love CPP

hihoCoder 1082 然而沼跃鱼早就看穿了一切

2016-10-07

描述#1082 : 然而沼跃鱼早就看穿了一切

Description

fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。

Input and Output

输入

输入包括多行。

每行是一个字符串,长度不超过200。

一行的末尾与下一行的开头没有关系。

输出

输出包含多行,为输入按照描述中变换的结果。

样例输入

The Marshtomp has seen it all before.

marshTomp is beaten by fjxmlhx!

AmarshtompB

样例输出

The fjxmlhx has seen it all before.

fjxmlhx is beaten by fjxmlhx!

AfjxmlhxB

Codes

#include <iostream>
#include <string>
#include <algorithm> 
#include <cctype>

using namespace std;

int main() {
    string str, temp;
    const string s1 = "marshtomp";
    const string s2 = "fjxmlhx";
    
    string::size_type a = s1.size();
    string::size_type b = s2.size();
    while (getline(cin, temp)) {
        str = temp;
        transform(str.begin(),str.end(),str.begin(),::tolower);
        
        string::size_type pos = 0;
        while ((pos=str.find(s1,pos))!=string::npos) {
            str.replace(pos, a, s2);
            temp.replace(pos,a,s2);
            pos+=b;
        }
        cout << temp << endl;
    }
    
    return 0;
}

Comments

Content