UVA —10361—Automatic Poetry

简介: UVA —10361—Automatic Poetry

题目描述

“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.


The Problem

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

s1s3s5

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 abel ur

wenn es haengt an der …

weil wir zu spaet zur <>oma amen

verpassten wir das …

u 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

解题思路:

这个题以字符串的形式输入,判断<>中的内容,第一行输出直接去掉<>就行了,第二行把刚刚<>中的内容交换一下输出。

程序代码:

#include<stdio.h>
#include<string.h>
char s1[100],s2[100],c1[100],c2[100],l1[100],l2[100];
int main()
{
  int cad,n,i,j,k,m,t,a,b,e,f;
  scanf("%d",&cad);
  getchar();
  while(cad--)
  {
    memset(s1,0,sizeof(s1));
    memset(s2,0,sizeof(s2));
    memset(c1,0,sizeof(c1));
    memset(c2,0,sizeof(c2));
    memset(l1,0,sizeof(l1));
    memset(l2,0,sizeof(l2));
    fgets(s1,sizeof(s1),stdin);
    fgets(s2,sizeof(s2),stdin);
    n=strlen(s1);
    m=strlen(s2); 
    for(j=0;j<n;j++)
    {
      if(s1[j]=='<'||s1[j]=='>')
        continue;
      printf("%c",s1[j]);
    }
    for(i=n-1;i>=0;i--)
    {
      if(s1[i]=='>')
        a=i;
      if(s1[i]=='<')
      {
        b=i; break;
      } 
    }   
    for(i=0;i<n;i++)
    {
      if(s1[i]=='<')
        e=i;
      if(s1[i]=='>')
      {
        f=i; break;
      }
    }
    for(i=0;i<m;i++)
    {
      if(s2[i]=='.')
      {
        for(i=b+1;i<a;i++)
          printf("%c",s1[i]);
        for(i=f+1;i<b;i++)
          printf("%c",s1[i]);
        for(i=e+1;i<f;i++)
          printf("%c",s1[i]);
        for(i=a+1;i<n-1;i++)
          printf("%c",s1[i]);
        break;
      }
      else
        printf("%c",s2[i]);
    }
    printf("\n");     
  }
  return 0;
} 


相关文章
|
安全 区块链
数字货币秒合约/交易所系统开发详细程序/案例项目/需求设计/方案逻辑/源码步骤
The development of a digital currency second contract/exchange system requires the following functions:
|
机器学习/深度学习 监控 算法
计算机视觉实战项目(图像分类+目标检测+目标跟踪+姿态识别+车道线识别+车牌识别)
计算机视觉实战项目(图像分类+目标检测+目标跟踪+姿态识别+车道线识别+车牌识别)
|
运维 网络虚拟化 5G
带你读《ONAP技术详解与应用实践》之一:网络自动化挑战及ONAP介绍
国内首部系统剖析ONAP的书籍,也是理论性与实战性兼具的网络自动化实践指导书!本书详细全面地介绍了网络自动化的挑战和发展趋势,以及ONAP的概况、架构设计理念、设计原则、各模块实现细节、关键特性、应用场景和案例实践等。通过本书读者可以深入理解ONAP,提升对网络自动化及相关领域的认知。作者及其团队成员均是华为网络开源领域的专家,长期参与社区的治理、贡献和回馈,致力于通过产业协作,打造统一的平台,降低集成成本,加快新技术导入,助力新一代网络运维系统升级。同时,本书也融入了作者及其团队在网络开源领域的深刻洞察和见解,书中分享了华为参与网络开源的实践经验,是电信网络转型的重要参考。
|
8月前
|
开发者 ice
实时云渲染中的NAT转发服务支持个人电脑秒变云渲染服务器
实时云渲染技术广泛应用于XR领域,助力数千客户完成云端部署。平行云推出的转发服务解决了家庭网络动态IP问题,使个人电脑成为实时云渲染服务器,按实际使用分钟数计费,无用户访问不收费。通过配置LarkXR的代理转发Server和ICE Server,开发者可轻松实现互联网访问内网XR应用,极大提升了开发、测试和演示的便利性。
128 11
|
10月前
|
Linux 数据库
Linux内核中的锁机制:保障并发操作的数据一致性####
【10月更文挑战第29天】 在多线程编程中,确保数据一致性和防止竞争条件是至关重要的。本文将深入探讨Linux操作系统中实现的几种关键锁机制,包括自旋锁、互斥锁和读写锁等。通过分析这些锁的设计原理和使用场景,帮助读者理解如何在实际应用中选择合适的锁机制以优化系统性能和稳定性。 ####
205 6
|
11月前
|
消息中间件 负载均衡 Cloud Native
云原生之旅:从容器到微服务的架构演变
在数字化转型的风潮中,云原生技术以其灵活性、可扩展性和弹性而备受青睐。本文将通过一个虚拟的故事,讲述一个企业如何逐步拥抱云原生,实现从传统架构向容器化和微服务架构的转变,以及这一过程中遇到的挑战和解决方案。我们将以浅显易懂的方式,探讨云原生的核心概念,并通过实际代码示例,展示如何在云平台上部署和管理微服务。
|
消息中间件 安全 Java
线程和进程的区别及应用场景
线程和进程的区别及应用场景
|
前端开发 iOS开发
通过css内修改input框placeholder样式
通过css内修改input框placeholder样式
251 1
|
消息中间件 负载均衡 Kafka
Kafka学习---2、kafka生产者、异步和同步发送API、分区、生产经验(一)
Kafka学习---2、kafka生产者、异步和同步发送API、分区、生产经验(一)
|
缓存 Java 开发者
Spring高手之路15——掌握Spring事件监听器的内部逻辑与实现
深入探索Spring的事件处理机制,从事件的层次传播、PayloadApplicationEvent的使用,到为何选择自定义事件。本文详细剖析了Spring 5.x的事件模型、事件发布源码、ApplicationEventMulticaster的作用以及事件广播的核心逻辑。通过详细的流程图与图示,读者可以更好地理解Spring事件传播、异步处理等关键概念,为成为Spring高手奠定坚实基础。
29010 26
Spring高手之路15——掌握Spring事件监听器的内部逻辑与实现

热门文章

最新文章