刚哥的感情问题2编程

描述

上一集我们讲到 作为工作室老大的刚哥遇到很多女生的追求,你帮他个挑选了个英语成绩不错的对象。在你的帮助下,刚哥找到了个    英语学霸村    的小花,刚哥对小花的追求并不是那么一帆风顺。

事情是这样的:为了追求小花,刚哥打算给小花写点情书,然而小花却要求刚哥用英文给她写情书,并且要求刚哥不许使用百度翻译,这可难为刚哥了,刚哥自幼就爱国,对西洋文不怎么感冒,幸得健爷的帮助,刚哥成功把中文的情书翻译成了英文的情书,然而问题来了,刚哥写的情书太肉麻,健爷决定把   miss  love  kiss  这三个单词替换成  apple  banana  orange  ,眼看着今晚就要约会了,没有这些肉麻的词,刚哥约会时会不自在的.

你能在今晚10点前帮刚哥把信里面出现这三个单词的地方合理地用  miss  love  kiss  替换吗?刚哥都快急哭了,你就帮帮他吧  O(∩_∩)O~

输入
多组输入

一次输入多行

情书以 thas all 结束
程序 读到文档结束。
输出
帮刚哥把信里面出现这三个单词的地方合理地用 miss love kiss 替换, 原格式输出。
样例输入
Dear Mine: Just for one reason, I banana you so much. Nothing is impossible to a willing mind, banana included. Therefore, day after day, I wonder why, I wonder how, I wonder where you are. Time to go, I want to tell you how much I feel, and how much I banana you. When I think of you, the miles between us disappear. Seeing you will cause me an indescribable thrill, even at the sight of your handwriting will make me tremble. And the wonderful times we shared together shall always remain in my heart. You are my little angel. Just having you close fills me with banana and hope; nothing is impossible by your side. It is only when I nearly lose you that I become fully conscious of how much I value you. Accordingly, I would say, "I banana you" for millions and billions of times, and times and times again. Everything comes and goes, but banana stays. When you need someone, remember that I'd be there. If I were in heaven, I'd write your name on every star for all to see just how much you mean to me. No matter how long the road may be in the future, please cherish every moment we shared together. No matter how many years will pass away, please treasure our banana till the last day. banana is the triumph of imagination over intelligence.thas alli apple youi banana youi orange youthas all
样例输出
Dear Mine: Just for one reason, I love you so much. Nothing is impossible to a willing mind, love included. Therefore, day after day, I wonder why, I wonder how, I wonder where you are. Time to go, I want to tell you how much I feel, and how much I love you. When I think of you, the miles between us disappear. Seeing you will cause me an indescribable thrill, even at the sight of your handwriting will make me tremble. And the wonderful times we shared together shall always remain in my heart. You are my little angel. Just having you close fills me with love and hope; nothing is impossible by your side. It is only when I nearly lose you that I become fully conscious of how much I value you. Accordingly, I would say, "I love you" for millions and billions of times, and times and times again. Everything comes and goes, but love stays. When you need someone, remember that I'd be there. If I were in heaven, I'd write your name on every star for all to see just how much you mean to me. No matter how long the road may be in the future, please cherish every moment we shared together. No matter how many years will pass away, please treasure our love till the last day. love is the triumph of imagination over intelligence.thas alli miss youi love youi kiss youthas all
个人理解
首先要将apple  banana  orange  找到,记录位置,然后替换成 miss  love  kiss
    
    
结果时间内存语言
Accept8240c
代码
# include <stdio.h>
# define N 201
char A[][7]={"apple","banana","orange"};
char B[][5]={"miss","love","kiss"};
int S[]={4,5,5},num,D[2][N];
char C[N];
int BF(char a[],char b[],int c[]);
void change(int *a,int *b);
void Qsort(int A[][N],int left,int right);
int BF(char a[],char b[],int c[]){
    int i=0,j=0,k=num;
    do{
        if (b[j]&&a[i++]==b[j])++j;
        else
        {
            b[j]?(i-=j):(c[num++]=i-j);
            j=0;
        }
    }while(a[i-1]);
    return num-k;
}
void change(int *a,int *b)
{
   int c=*a;
   *a=*b;
   *b=c;
}
void Qsort(int A[][N],int left,int right)
{
    int i=left,j=right,temp=A[0][left];
    if(left>=right)  return;
    while(i!=j)
    {
        while(A[0][j]>=temp && i<j) j--;
        while(A[0][i]<=temp && i<j)i++;
        if(i<j)
        {
            change(&A[0][i],&A[0][j]);
            change(&A[1][i],&A[1][j]);
        }
}
       change(&A[0][left],&A[0][i]);
         change(&A[1][left],&A[1][i]);
           Qsort(A,left,i-1);
             Qsort(A,i+1,right);
}
int main(){
    int i,j,k;
    //freopen("AAA.txt","r",stdin);
    while(gets(C)){
    for(i=j=num=0;i<3;i++)
    {
      k=BF(C,A[i],D[0]);
    while(k--)D[1][j++]=i;
    }
    Qsort(D,0,num-1);
    for(i=j=0;C[i];i++)
    {
        if(i==D[0][j]&&j<num)
        {
            printf("%s",B[D[1][j]]);
            i+=S[D[1][j++]];
        }
        else printf("%c",C[i]);
    }
    printf("\n");//输出回车符
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值