Time Limit:
1000ms
Case Time Limit:
1000ms
Memory Limit:
256MB
-
The Marshtomp has seen it all before. marshTomp is beaten by fjxmlhx! AmarshtompB
Sample Output
-
The fjxmlhx has seen it all before. fjxmlhx is beaten by fjxmlhx! AfjxmlhxB
Description
fjxmlhx is fed up with endless marshtomps on the internet. So he turns to you to write a program to change all occurrence of “marshtomp” ( the name is not case-sensitive) to “fjxmlhx”.
Input
The input contains multiple lines.
Each line is a string which length is no more than 200.
The end of one line don’t connect with the head of the next line.
Output
The output contains multiple lines which are the result after the changes in the description.
String代码
:
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
//typedef unsigned int size_t;
int my_stricmp(string &s1,string &s2)
{
if(s1.length()==s2.length())
{
for(size_t i=0;i<s1.length();i++)
{
s1[i]=tolower(s1[i]);
}
if(s1==s2)
return 0;
else
return 1;
}
}
void process(string &str)
{
string ori="marshtomp";
string res="fjxmlhx";
string tmp;
size_t len=ori.length();
int ans;
bool flag=false;
for(size_t i=0;i<str.length();i++)
{
if(str.length()-i>=ori.length())
{
tmp=str.substr(i,ori.length());
ans=my_stricmp(tmp,ori);
if(0==ans)
{
str=str.replace(i,len,res);
flag=true;
i+=len;
continue;
}
}
}
if(true==flag)
cout<<str<<endl;
}
int main()
{
char str[200];
while(cin.getline(str,200))
{
string s(str);
if(s.length()<=200)
process(s);
}
return 0;
}
char代码:
#include<iostream>
#include <string.h>
using namespace std;
typedef long long ll;
int main(int argc , const char * argv[])
{
char s[200];
while (cin.getline(s,200))
{
char f[] = "marshtomp";
char t[] = "fjxmlhx";
int sl = strlen(s);
int fl= strlen(f);
int tl = strlen(t);
for (int i =0; i<strlen(s); i++)
{
int j = 0;
int k =i;
while (s[k] == f[j] || s[k] == (f[j]-32))
{
k++;
j++;
if (j == fl)
{
for (int q = i; (q-i) < tl; q++)
{
s[q] = t[q-i];
}
for (int q = i+tl; q<strlen(s); q++)
{
if ( s[q+fl-tl] != '\0')
{
s[q] = s [q+fl-tl];
}
else
{
s[q] = '\0';
}
}
}
}
}
cout<<s<<endl;
}
}