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

Time Limit: 1000ms
Case Time Limit: 1000ms
Memory Limit: 256MB

Description

14184646038225.jpg

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




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值