刚哥遇到了感情问题(二)--南洋ACM-1294

2023-11-09 18:20

本文主要是介绍刚哥遇到了感情问题(二)--南洋ACM-1294,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

刚哥遇到了感情问题(二)

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 1
描述

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

事情是这样的:为了追求小花,刚哥打算给小花写点情书,然而小花却要求刚哥用英文给她写情书,并且要求刚哥不许使用百度翻译,这可难为刚哥了,刚哥自幼就爱国,对西洋文不怎么感冒,幸得健爷的帮助,刚哥成功把中文的情书翻译成了英文的情书,然而问题来了,刚哥写的情书太肉麻,健爷决定把   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
来源
自创
上传者

1483523635

AC情况:


代码《C语言》:

/*程序大体思路:char A[][7]={"apple","banana","orange"};  //A->Bchar B[][5]={"miss","love","kiss"};int  S[]={5,6,6};A[i]如果在字符串中匹配成功 需要替换成 B[i]输入了字符串C[] 后用 "apple","banana","orange" 分别与C[]匹配A[i]匹配成功,则对应的替换成 B[i]为了节省时间 我们不进行替换 而是得到替换的位置时输出"miss","love"或"kiss"然后i跳过"apple","banana"或"orange"的长度 即i+=S[i]那我们还需要在A[i]匹配成功时 再另外保存一个i 先举个例子比如 C="apple orange banana you"则 A[0]="apple"与C匹配后得到匹配的数组下标0    另外记个 0A[1]="banana"与C匹配后得到匹配的数组下标13  另外记个 1A[2]="orange"与C匹配后得到匹配的数组下标6   另外记个 2得到D[2][3]={{0,0},{13,1},{6,2}}以D[0]为主顺序 升序排列  得到 D[2][3]={{0,0},{6,2},{13,1}}然后在输出C的过程中 遇到 0 6 13 我们就知道对应输出 B[0],B[2],B[1].上句话就是:        遇到 D[0][0] D[0][1] D[0][2]我们就知道对应输出 B[D[1][0]],B[D[1][1]],B[D[1][2]]即当我们得到D数组并升序(D数组中存储的匹配的总个数为num):for(i=k=0;C[i];i++){   //输出C字符串if(i==D[0][k]&&k<num)//当i到达 D[0][k]的位置{printf("%s",B[D[1][k]]);//输出B[D[1][k]]i+=S[D[1][k++]];//i加上 "apple","banana"或者"orange"的长度 并且D数组移动到下一个位置}else printf("%c",C[i]);//如果没有到达D的位置 原样输出}
*/
# include <stdio.h>
# define N 201
char A[][7]={"apple","banana","orange"};  //A->B
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[]);//BF算法 a为主串,b为被检验的串`返回b在a中的第一个下标 若无返回0
void change(int *a,int *b);//交换函数
void Qsort(int A[][N],int left,int right);//快速排序 升序
int main(){int i,j,k;//freopen("AAA.txt","r",stdin);while(gets(C)){for(i=j=num=0;i<3;i++)//用 A[i]匹配C 返回匹配的个数{k=BF(C,A[i],D[0]);//k记录A[i]匹配的个数while(k--)D[1][j++]=i;//D[1]用来存储i}Qsort(D,0,num-1);//以A[0]升序 从下标0---  num-1  一共num个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;
}
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){//交换函数 交换a 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);
}

代码2:


/*程序大体思路:char A[][7]={"apple","banana","orange"};  //A->Bchar B[][5]={"miss","love","kiss"};int  S[]={5,6,6};A[i]如果在字符串中匹配成功 需要替换成 B[i]输入了字符串C[] 后用 "apple","banana","orange" 分别与C[]匹配A[i]匹配成功,则对应的替换成 B[i]为了节省时间 我们不进行替换 而是得到替换的位置时输出"miss","love"或"kiss"然后i跳过"apple","banana"或"orange"的长度 即i+=S[i]那我们还需要在A[i]匹配成功时 再另外保存一个i 先举个例子比如 C="apple orange banana you"则 A[0]="apple"与C匹配后得到匹配的数组下标0    另外记个 0A[1]="banana"与C匹配后得到匹配的数组下标13  另外记个 1A[2]="orange"与C匹配后得到匹配的数组下标6   另外记个 2得到D[2][3]={{0,0},{13,1},{6,2}}以D[0]为主顺序 升序排列  得到 D[2][3]={{0,0},{6,2},{13,1}}然后在输出C的过程中 遇到 0 6 13 我们就知道对应输出 B[0],B[2],B[1].上句话就是:        遇到 D[0][0] D[0][1] D[0][2]我们就知道对应输出 B[D[1][0]],B[D[1][1]],B[D[1][2]]即当我们得到D数组并升序(D数组中存储的匹配的总个数为num):for(i=k=0;C[i];i++){   //输出C字符串if(i==D[0][k]&&k<num)//当i到达 D[0][k]的位置{printf("%s",B[D[1][k]]);//输出B[D[1][k]]i+=S[D[1][k++]];//i加上 "apple","banana"或者"orange"的长度 并且D数组移动到下一个位置}else printf("%c",C[i]);//如果没有到达D的位置 原样输出}
*/
# include <stdio.h>
# define N 201
char A[][7]={"apple","banana","orange"};  //A->B
char B[][5]={"miss","love","kiss"};
int S[]={4,5,5},D[2][N];
char C[N];
int BF(char a[],char b[],int c[]);//BF算法 a为主串,b为被检验的串`返回b在a中的第一个下标 若无返回0
void change(int *a,int *b);//交换函数
void Qsort(int A[][N],int left,int right);//快速排序 升序
int main(){int i,j,k;//freopen("AAA.txt","r",stdin);while(gets(C)){for(i=j=D[0][0]=0;i<3;i++)//用 A[i]匹配C 返回匹配的个数{k=BF(C,A[i],D[0]);//k记录A[i]匹配的个数while(k--)D[1][++j]=i;//D[1]用来存储i}Qsort(D,1,D[0][0]-1);//以A[0]升序 从下标0---  num-1  一共num个for(i=0,j=1;C[i];i++){//输出if(i==D[0][j]&&j<=D[0][0]){printf("%s",B[D[1][j]]);i+=S[D[1][j++]];}else printf("%c",C[i]);}printf("\n");//输出回车符}return 0;
}
int BF(char a[],char b[],int c[]){int i=0,j=0,k=c[0];do{if (b[j]&&a[i++]==b[j])++j;else{b[j]?(i-=j):(c[++c[0]]=i-j);j=0;}}while(a[i-1]);return c[0]-k;
}
void change(int *a,int *b){//交换函数 交换a 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]);}
}if(i!=left){change(&A[0][left],&A[0][i]);change(&A[1][left],&A[1][i]);}Qsort(A,left,i-1);Qsort(A,i+1,right);
}


这篇关于刚哥遇到了感情问题(二)--南洋ACM-1294的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/377815

相关文章

线上Java OOM问题定位与解决方案超详细解析

《线上JavaOOM问题定位与解决方案超详细解析》OOM是JVM抛出的错误,表示内存分配失败,:本文主要介绍线上JavaOOM问题定位与解决方案的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录一、OOM问题核心认知1.1 OOM定义与技术定位1.2 OOM常见类型及技术特征二、OOM问题定位工具

Vue3绑定props默认值问题

《Vue3绑定props默认值问题》使用Vue3的defineProps配合TypeScript的interface定义props类型,并通过withDefaults设置默认值,使组件能安全访问传入的... 目录前言步骤步骤1:使用 defineProps 定义 Props步骤2:设置默认值总结前言使用T

Web服务器-Nginx-高并发问题

《Web服务器-Nginx-高并发问题》Nginx通过事件驱动、I/O多路复用和异步非阻塞技术高效处理高并发,结合动静分离和限流策略,提升性能与稳定性... 目录前言一、架构1. 原生多进程架构2. 事件驱动模型3. IO多路复用4. 异步非阻塞 I/O5. Nginx高并发配置实战二、动静分离1. 职责2

解决升级JDK报错:module java.base does not“opens java.lang.reflect“to unnamed module问题

《解决升级JDK报错:modulejava.basedoesnot“opensjava.lang.reflect“tounnamedmodule问题》SpringBoot启动错误源于Jav... 目录问题描述原因分析解决方案总结问题描述启动sprintboot时报以下错误原因分析编程异js常是由Ja

MySQL 表空却 ibd 文件过大的问题及解决方法

《MySQL表空却ibd文件过大的问题及解决方法》本文给大家介绍MySQL表空却ibd文件过大的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录一、问题背景:表空却 “吃满” 磁盘的怪事二、问题复现:一步步编程还原异常场景1. 准备测试源表与数据

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

SysMain服务可以关吗? 解决SysMain服务导致的高CPU使用率问题

《SysMain服务可以关吗?解决SysMain服务导致的高CPU使用率问题》SysMain服务是超级预读取,该服务会记录您打开应用程序的模式,并预先将它们加载到内存中以节省时间,但它可能占用大量... 在使用电脑的过程中,CPU使用率居高不下是许多用户都遇到过的问题,其中名为SysMain的服务往往是罪魁

MySQ中出现幻读问题的解决过程

《MySQ中出现幻读问题的解决过程》文章解析MySQLInnoDB通过MVCC与间隙锁机制在可重复读隔离级别下解决幻读,确保事务一致性,同时指出性能影响及乐观锁等替代方案,帮助开发者优化数据库应用... 目录一、幻读的准确定义与核心特征幻读 vs 不可重复读二、mysql隔离级别深度解析各隔离级别的实现差异

C++ vector越界问题的完整解决方案

《C++vector越界问题的完整解决方案》在C++开发中,std::vector作为最常用的动态数组容器,其便捷性与性能优势使其成为处理可变长度数据的首选,然而,数组越界访问始终是威胁程序稳定性的... 目录引言一、vector越界的底层原理与危害1.1 越界访问的本质原因1.2 越界访问的实际危害二、基

Python多线程应用中的卡死问题优化方案指南

《Python多线程应用中的卡死问题优化方案指南》在利用Python语言开发某查询软件时,遇到了点击搜索按钮后软件卡死的问题,本文将简单分析一下出现的原因以及对应的优化方案,希望对大家有所帮助... 目录问题描述优化方案1. 网络请求优化2. 多线程架构优化3. 全局异常处理4. 配置管理优化优化效果1.