#1082 : 然而沼跃鱼早就看穿了一切
2015-04-16 19:34
267 查看
时间限制:1000ms
单点时限:1000ms
内存限制:256MB
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。
输入包括多行。
每行是一个字符串,长度不超过200。
一行的末尾与下一行的开头没有关系。
输出包含多行,为输入按照描述中变换的结果。
样例输入
分析:暴力搜就不说了。说一种用状态机的方法,学过编译原理的童鞋知道确定性状态机,这个是一个检测marshtomp字符串的题目。看程序吧,非常简单,状态从0到8,每检测到一个这个单词的字母就状态转换,
单点时限:1000ms
内存限制:256MB
描述
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。
输入
输入包括多行。每行是一个字符串,长度不超过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
分析:暴力搜就不说了。说一种用状态机的方法,学过编译原理的童鞋知道确定性状态机,这个是一个检测marshtomp字符串的题目。看程序吧,非常简单,状态从0到8,每检测到一个这个单词的字母就状态转换,
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main() { char str[201]; const char str_AZ[]="MARSHTOMP"; const char str_az[]="marshtomp"; while(cin.getline(str,200)) { int i=-1; int state=0; char *s; while(str[++i]!='\0') { if(state==0) { if(str[i]=='M'||str[i]=='m') { s = &str[i]; state++; } } else if(state==8) { if(str[i]==str_AZ[state] || str[i]==str_az[state]) { strcpy(s,"fjxmlhx"); strcpy(s+7,str+i+1); i-=2; } state=0; } else { if(str[i]==str_AZ[state] || str[i]==str_az[state]) state++; else state=0; } } printf("%s\n",str); } return 0; }
相关文章推荐
- hihoCoder:#1082 然而沼跃鱼早就看穿了一切
- hihoCoder#1082 然而沼跃鱼早就看穿了一切
- HihoCoder#1082: 然而沼跃鱼早就看穿了一切
- #1082 : 然而沼跃鱼早就看穿了一切
- #1082 : 然而沼跃鱼早就看穿了一切(AC版)
- [HIHO1082]然而沼跃鱼早就看穿了一切(字符串水题)
- hiho #1082 : 然而沼跃鱼早就看穿了一切
- hihoCoder - 1082 - 然而沼跃鱼早就看穿了一切 (字符串处理!!)
- hiho 1082 : 然而沼跃鱼早就看穿了一切
- 【hihocoder1082】然而沼跃鱼早就看穿了一切——字符串
- hihoCoder #1082 : 然而沼跃鱼早就看穿了一切(字符串处理)
- hihoCoder#1082 : 然而沼跃鱼早就看穿了一切(做题总结)
- Hihocoder #1082 : 然而沼跃鱼早就看穿了一切 暴力
- hihocoder编程练习:#1082 : 然而沼跃鱼早就看穿了一切
- 然而沼跃鱼早就看穿了一切 hihoCoder1082
- 【hihoCoder】#1082 : 然而沼跃鱼早就看穿了一切
- hihoCoder 1082 : 然而沼跃鱼早就看穿了一切
- #1082 : 然而沼跃鱼早就看穿了一切
- hiho 1082 : 然而沼跃鱼早就看穿了一切
- HihoCoder#1082 : 然而沼跃鱼早就看穿了一切