uva 10361 Automatic Poetry(字符串处理)

2024-06-05 05:48

本文主要是介绍uva 10361 Automatic Poetry(字符串处理),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Automatic Poetry

Input: standard input

Output: standard output

Time Limit: 2 seconds

Memory Limit: 32 MB

 

“Oh God”, Lara Croft exclaims, “it’s one of these dumb riddles again!”

 

In Tomb Raider XIV, Lara is, as ever, gunning her way through ancient Egyptian pyramids, prehistoric caves and medival hallways. Now she is standing in front of some important Germanic looking doorway and has to solve a linguistic riddle to pass. As usual, the riddle is not very intellectually challenging.

 

This time, the riddle involves poems containing a “Schuttelreim”. An example of a Schuttelreim is the following short poem:

 

Ein Kind halt seinen Schnabel nur,

wenn es hangt an der Nabelschnur.        

 

/*German contestants please forgive me. I had to modify something as they were not appearing correctly in plain text format*/

 

A Schuttelreim seems to be a typical German invention. The funny thing about this strange type of poetry is that if somebody gives you the first line and the beginning of the second one, you can complete the poem yourself. Well, even a computer can do that, and your task is to write a program which completes them automatically. This will help Lara concentrate on the “action” part of Tomb Raider and not on the “intellectual” part.

Input

The input will begin with a line containing a single number n. After this line follow n pairs of lines containing Schuttelreims. The first line of each pair will be of the form

s1<s2>s3<s4>s5

 

where the si are possibly empty, strings of lowercase characters or blanks. The second line will be a string of lowercase characters or blanks ending with three dots “...”. Lines will we at most 100 characters long.

Output

For each pair of Schuttelreim lines l1 and l2 you are to output two lines c1 and c2 in the following way: c1 is the same as l1 only that the bracket marks “<” and “>” are removed. Line c2 is the same as l2 , except that instead of the three dots the string s4s3s2s5 should appear.

Sample Input

3

ein kind haelt seinen <schn>abel <n>ur

wenn es haengt an der ...

weil wir zu spaet zur <>oma <k>amen

verpassten wir das ...

<d>u <b>ist

...

Sample Output

ein kind haelt seinen schnabel nur

wenn es haengt an der nabel schnur

weil wir zu spaet zur oma kamen

verpassten wir das koma amen

du bist

bu dist

题目大意:每组数据给出两组字符串,string1:s1<s2>s3<s4>s5的形式,转化后输出s1s2s3<s4s5.string2:s6...,其中"..."替换成s4s3s2s5.

解题思路:将s1~s6分别存储,再输出。

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;#define N 105int main(){int n;char str[N], tem[5][N];cin >> n;getchar();while (n--){// Init.memset(str, 0, sizeof(str));memset(tem, 0, sizeof(tem));// Read.gets(str);// Change.int k = strlen(str);int cnt = 0, t = 0;for (int i = 0; i < k; i++){if (str[i] == '<'){ tem[cnt][t] = '\0';t = 0;cnt++;}else if (str[i] =='>'){tem[cnt][t] = '\0';t = 0;cnt++;}elsetem[cnt][t++] = str[i];}gets(str);cout << tem[0] << tem[1] << tem[2] << tem[3] << tem[4] << endl;for (int i = 0; str[i] != '\0'; i++)if (str[i] =='.')break;elseputchar(str[i]);cout << tem[3] << tem[2] << tem[1] << tem[4] << endl;}return 0;}

这篇关于uva 10361 Automatic Poetry(字符串处理)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Springboot处理跨域的实现方式(附Demo)

《Springboot处理跨域的实现方式(附Demo)》:本文主要介绍Springboot处理跨域的实现方式(附Demo),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录Springboot处理跨域的方式1. 基本知识2. @CrossOrigin3. 全局跨域设置4.

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤

Python实现自动化接收与处理手机验证码

《Python实现自动化接收与处理手机验证码》在移动互联网时代,短信验证码已成为身份验证、账号注册等环节的重要安全手段,本文将介绍如何利用Python实现验证码的自动接收,识别与转发,需要的可以参考下... 目录引言一、准备工作1.1 硬件与软件需求1.2 环境配置二、核心功能实现2.1 短信监听与获取2.

Python使用date模块进行日期处理的终极指南

《Python使用date模块进行日期处理的终极指南》在处理与时间相关的数据时,Python的date模块是开发者最趁手的工具之一,本文将用通俗的语言,结合真实案例,带您掌握date模块的六大核心功能... 目录引言一、date模块的核心功能1.1 日期表示1.2 日期计算1.3 日期比较二、六大常用方法详

利用Go语言开发文件操作工具轻松处理所有文件

《利用Go语言开发文件操作工具轻松处理所有文件》在后端开发中,文件操作是一个非常常见但又容易出错的场景,本文小编要向大家介绍一个强大的Go语言文件操作工具库,它能帮你轻松处理各种文件操作场景... 目录为什么需要这个工具?核心功能详解1. 文件/目录存javascript在性检查2. 批量创建目录3. 文件

python中字符串拼接的几种方法及优缺点对比详解

《python中字符串拼接的几种方法及优缺点对比详解》在Python中,字符串拼接是常见的操作,Python提供了多种方法来拼接字符串,每种方法有其优缺点和适用场景,以下是几种常见的字符串拼接方法,需... 目录1. 使用 + 运算符示例:优缺点:2. 使用&nbsjsp;join() 方法示例:优缺点:3

java字符串数字补齐位数详解

《java字符串数字补齐位数详解》:本文主要介绍java字符串数字补齐位数,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java字符串数字补齐位数一、使用String.format()方法二、Apache Commons Lang库方法三、Java 11+的St

C++字符串提取和分割的多种方法

《C++字符串提取和分割的多种方法》在C++编程中,字符串处理是一个常见的任务,尤其是在需要从字符串中提取特定数据时,本文将详细探讨如何使用C++标准库中的工具来提取和分割字符串,并分析不同方法的适用... 目录1. 字符串提取的基本方法1.1 使用 std::istringstream 和 >> 操作符示

Java使用多线程处理未知任务数的方案介绍

《Java使用多线程处理未知任务数的方案介绍》这篇文章主要为大家详细介绍了Java如何使用多线程实现处理未知任务数,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 知道任务个数,你可以定义好线程数规则,生成线程数去跑代码说明:1.虚拟线程池:使用 Executors.newVir

一文带你深入了解Python中的GeneratorExit异常处理

《一文带你深入了解Python中的GeneratorExit异常处理》GeneratorExit是Python内置的异常,当生成器或协程被强制关闭时,Python解释器会向其发送这个异常,下面我们来看... 目录GeneratorExit:协程世界的死亡通知书什么是GeneratorExit实际中的问题案例