您的位置:首页 > 其它

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

2015-03-02 10:49 961 查看
Time Limit:1000ms
Case Time Limit:1000ms
Memory Limit:256MB


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.

Sample Input
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


先上string代码,不知为什么编译通不过WA,也请看到的大神请帮我分析下为什么通不过。在VS上测试一切正常,然后奉上char代码,AC.

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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: