A Tale from the Dark Side of The Moon

1、http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2092

2、错在只要字符串中出现EOF就结束,另外需要注意i+3,i-1的边界

3、

A Tale from the Dark Side of The Moon

Time Limit: 1000MS    Memory limit: 65536K

题目描述

Us: So why don’t you just recompile the program Us: What about "ddd" and "dddd"? How does it on the new hardware? behave then?
Them: We cannot. We lost the source code. Them: Where in English will you find a "dddd" or even a "ddd"? Haven’t you been listening?
Us: How typical! What does the program do? Do you have any documentation?
Them: The manual page does mention something about the documentation in the source code.
Us: A manual page is good. What does it say?
Them: Just one line: “See the source code for more information.”
Us: Argh! What do you know about the program?
Them: Well, it seems to be taking simple text, similar to that found in an English dictionary, and printing it after some modification.
Us: What kind of modification?
Them: It removes any character that is not a lowercase letter. But not white spaces. White spaces are preserved as seen in the input.
Us: Do you have a sample input/output?
Them: Plenty. Here’s one. (see next page.)
Us: This is rather small! Did you try it on anything
bigger?
Us: Oops. We’ll pay more attention. Anything else?
Another one of them: There is also the "vv" thingy.
Us: What about "vv"?
Them: Every "vv" is replaced with a "m".Yet another one of them: No, wait! That was a printer problem. it had nothing to do with the program.
Remember?
Them: Oh, that’s right.thingy. Forget about the "vv"
Us: What about the "dd" thingy? Was that just a printer problem too?
Them: No. That was the program.
Us: What else?
Them: One last thing.every "ei" with "ie".It seems to be replacing
Us: Every one of them?
Them: Except if it comes right after "c" then it remains as is.
Them: It works on any text as long as the lines are Them: No, we just remembered one more thing: It less then eighty characters wide. It doesn’t seem replaces the sequence "pink" with "floyd" any to mind working on lengthy documents. But it where in the text.does terminate once it sees the sequence "EOF" (without the double quotes.)
One of them: Don’t forget to tell them about the Us: What?! Who wrote this program? Why do you "dd" thingy. need it in the first place?
Us: : What "dd" thingy?
Them: We think it will increase our chances of going to Banff in April 2008 if we get it right.
Them: Whenever it sees a pair of small letter "d",one right after the other, it replaces them with "p".
Us: Makes sense. That’s all, right?
Us: Yeah! Right.
Us: Why?
Them: Who knows? It just does that!

输入

输出

示例输入

unpinked is an 8 letter word. Honest!
vv is ok, d123d is ok, 123dd is not
i received mail from        liechtenstein
 ..  ...adding means to imitat.#$!%%$e
EOF

4、代码:

#include<stdio.h>
#include<string.h>
char str[100];
char a[100];
int visit[100];
int main()
{
    int j;
    while(gets(str))
    {
        memset(visit,0,sizeof(visit));
        memset(a,0,sizeof(a));
        //printf("%s",str);
        //if(strcmp(str,"EOF")==0)
        //break;
        int flag=0;
        int l=strlen(str);
        for(int i=0;i<strlen(str);i++)
        {
            if(i+3<l&&str[i]=='p'&&str[i+1]=='i'&&str[i+2]=='n'&&str[i+3]=='k'&&visit[i]==0&&visit[i+1]==0&&visit[i+2]==0&&visit[i+3]==0)
            {
                printf("floyd");
                visit[i]=1;
                visit[i+1]=1;
                visit[i+2]=1;
                visit[i+3]=1;
            }
            else if(i+1<l&&str[i]=='e'&&str[i+1]=='i'&&visit[i]==0&&visit[i+1]==0)
            {
                if((str[i-1]!='c'&&i-1>=0)||(i==0))
                {printf("ie");
                }
                else
                {
                    printf("ei");
                }
                visit[i]=1;
                visit[i+1]=1;
            }
            else if(i+1<l&&str[i]=='d'&&str[i+1]=='d'&&visit[i]==0&&visit[i+1]==0)
            {
               printf("p");
                visit[i]=1;
                visit[i+1]=1;
            }
            else if((str[i]==' '&&visit[i]==0)||(str[i]>='a'&&str[i]<='z'&&visit[i]==0))
            {
                printf("%c",str[i]);
                visit[i]=1;
            }
            else if(str[i]=='E'&&str[i+1]=='O'&&str[i+2]=='F'&&i+2<l)
            {
                flag=1;
                break;
            }
        }

        if(flag==1)
        break;
        printf("\n");
    }
    return 0;
}
/*
unpinked is an 8 letter word. Honest!
vv is ok, d123d is ok, 123dd is not
i received mail from        liechtenstein
 ..  ...adding means to imitat.#$!%%$e
EOF
*/


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值