poj 3510

A Tale from the Dark Side of the Moon
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2623 Accepted: 742

Description

Us: So why don’t you just recompile the program on the new hardware?

Them: We cannot. We lost the source code.

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 section.)

Us: This is rather small! Did you try it on anything bigger?

Them: It works on any text as long as the lines are less then eighty characters wide. It doesn’t seem to mind working on lengthy documents. But it does terminate once it sees the sequence "EOF" (without the double quotes.)

One of them: Don’t forget to tell them about the "dd" thingy.

Us: What "dd" thingy?

Them: Whenever it sees a pair of small letter "d", one right after the other, it replaces them with "p".

Us: Why?

Them: Who knows? It just does that!

Us: What about "ddd" and "dddd"? How does it behave then?

Them: Where in English will you find a "dddd" or even a "ddd"? Haven’t you been listening?

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. Forget about the "vv" thingy.

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. It seems to be replacing every "ei" with "ie".

Us: Every one of them?

Them: Except if it comes right after "c" then it remains as is.

Us: Makes sense. That’s all, right?

Them: No, we just remembered one more thing: It replaces the sequence "pink" with "floyd" anywhere in the text.

Us: What?! Who wrote this program? Why do you need it in the first place?

Them: We think it will increase our chances of going to Banff in April 2008 if we get it right.

Us: Yeah! Right.

Sample Input

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

Sample Output

unfloyded is an  letter word onest
vv is ok dd is ok p is not
i received mail from        liechtenstien
   aping means to imitate
题意:dd换成p,pink换成floyd,ei当前面是c时不变,否则输出ie,只保留小写字母与空格。结束时EOF位置不确定。
#include<stdio.h>
#include<string.h>
char str[100];
int main()
{
    while(gets(str))
    {
        int f=0;
        int len=strlen(str);
        for(int i=0; i<len;)
        {

            if(str[i]=='E'&&str[i+1]=='O'&&str[i+2]=='F')
            {
                f=1;
                break;
            }
            if((str[i]<'a'||str[i]>'z')&&str[i]!=' ')
            {
                i++;
                continue;
            }

            if(str[i]=='d'&&str[i+1]=='d')
            {
                printf("p");
                i+=2;
                continue;
            }
            else if(str[i]=='e'&&str[i+1]=='i')
            {
                if(str[i-1]=='c')
                {
                    printf("ei");
                }
                else
                {
                    printf("ie");
                }
                i+=2;
                continue;
            }
            else if(str[i]=='p')
            {
                if(str[i+1]=='i'&&str[i+2]=='n'&&str[i+3]=='k')
                {
                    printf("floyd");
                    i+=4;
                    continue;
                }
            }
            printf("%c",str[i]);
            i++;
        }
        if(f==1)
            break;
        printf("\n");

    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值