UVA之10361 - Automatic Poetry

简介:

Problem I

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


TUD Programming Contest



【题意】:

输入:

输入N组测试用例,每组输入两个字符串。

第一个字符串格式:s1<s2>s3<s4>s5

s1,s2,s3,s3,s4,s5都可以为空或者不存在或者全是小写字符

第二个字符串格式:s ....

输出:

每组测试用例输出两个字符串。

第一个字符串格式:s1s2s3s4s5

第二个字符串格式:ss4s3s2s5

【代码】:

[cpp]  view plain copy
  1. /********************************* 
  2. *   日期:2013-4-26 
  3. *   作者:SJF0115 
  4. *   题号: 题目10361 - Automatic Poetry 
  5. *   来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1302 
  6. *   结果:AC 
  7. *   来源:UVA 
  8. *   总结: 
  9. **********************************/  
  10. #include<stdio.h>  
  11. #include<string.h>  
  12. #define N 110  
  13. int main (){  
  14.     int i,j,Case,lena,lenb;  
  15.     char a[N],b[N],s[N],s1[N],s2[N],s3[N],s4[N],s5[N];  
  16.     //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);    
  17.     while(scanf("%d\n",&Case) != EOF){  
  18.         while(Case--){  
  19.             gets(a);  
  20.             gets(b);  
  21.             lena = strlen(a);  
  22.             //第一个子串  
  23.             for(j = 0,i = 0;a[i] != '<';i++,j++){  
  24.                 s1[j] = a[i];  
  25.             }  
  26.             s1[j] = '\0';  
  27.             //printf("%s\n",s1);  
  28.             //第二个子串  
  29.             for(i = i+1,j = 0;a[i] != '>';i++,j++){  
  30.                 s2[j] = a[i];  
  31.             }  
  32.             s2[j] = '\0';  
  33.             //printf("%s\n",s2);  
  34.             //第三个子串  
  35.             for(i = i+1,j = 0;a[i] != '<';i++,j++){  
  36.                 s3[j] = a[i];  
  37.             }  
  38.             s3[j] = '\0';  
  39.             //printf("%s\n",s3);  
  40.             //第四个子串  
  41.             for(i = i+1,j = 0;a[i] != '>';i++,j++){  
  42.                 s4[j] = a[i];  
  43.             }  
  44.             s4[j] = '\0';  
  45.             //printf("%s\n",s4);  
  46.             //第五个子串  
  47.             for(i = i+1,j = 0;i < lena;i++,j++){  
  48.                 s5[j] = a[i];  
  49.             }  
  50.             s5[j] = '\0';  
  51.             //printf("%s\n",s5);  
  52.             //第二个字符串  
  53.             for(i = 0,j = 0;b[i] != '.';i++,j++){  
  54.                 s[j] = b[i];  
  55.             }  
  56.             s[j] = '\0';  
  57.             //printf("%s\n",s);  
  58.             //输出  
  59.             printf("%s%s%s%s%s\n",s1,s2,s3,s4,s5);  
  60.             printf("%s%s%s%s%s\n",s,s4,s3,s2,s5);  
  61.         }  
  62.     }  
  63.     return 0;  
  64. }  
  65.   
  66.       


[cpp]  view plain copy
  1. #include<iostream>  
  2. #include<string>  
  3. using namespace std;  
  4.   
  5. #define MAXN 102  
  6. string a1, a2;  
  7.   
  8. void solve()  
  9. {  
  10.     int p1 = a1.find('<', 0);  
  11.     int p2 = a1.find('>', 0);  
  12.     int p3 = a1.find('<', p2+1);  
  13.     int p4 = a1.find('>', p2+1);  
  14.     string s1 = a1.substr(0, p1);  
  15.     string s2 = a1.substr(p1+1, p2-p1-1);  
  16.     string s3 = a1.substr(p2+1, p3-p2-1);  
  17.     string s4 = a1.substr(p3+1, p4-p3-1);  
  18.     string s5 = a1.substr(p4+1);  
  19.     cout<<s1<<s2<<s3<<s4<<s5<<endl;  
  20.     a2.replace(a2.length()-3, 3, s4+s3+s2+s5);  
  21.     cout<<a2<<endl;  
  22. }  
  23.   
  24. int main()  
  25. {  
  26.     int t;  cin>>t;  
  27.     cin.get();  
  28.     while(t--)  
  29.     {  
  30.         getline(cin, a1);  
  31.         getline(cin, a2);  
  32.         solve();  
  33.     }  
  34. }  
目录
相关文章
|
XML 监控 Dubbo
Dubbo怎么配置监控中心
**摘要:** 本文介绍了如何配置Dubbo的简单监控中心。首先,通过添加`&lt;dubbo:monitor protocol=&quot;registry&quot; /&gt;`到配置文件启用监控。接着,修改`dubbo.properties`设置Zookeeper地址。启动监控中心,服务提供者和消费者需添加`monitorEnabled=&quot;true&quot;`以开启监控功能。配置完成后,监控中心的Web界面能展示服务状态和性能指标,助力开发者和运维人员实时监控服务健康。
254 0
|
存储 Windows Python
【已解决】右键以某应用打开xx文件时,没有“始终”选项怎么办
【已解决】右键以某应用打开xx文件时,没有“始终”选项怎么办
|
数据建模 数据挖掘 物联网
《全链路数据治理-智能数据建模 》——客户案例:汽车行业数据建模最佳实践(2)
《全链路数据治理-智能数据建模 》——客户案例:汽车行业数据建模最佳实践(2)
336 0
算数右移和逻辑右移的区别及逻辑运算的窍门
算数右移和逻辑右移的区别及逻辑运算的窍门
1386 0
|
存储 JavaScript 前端开发
|
前端开发 JavaScript Java
基于SSM的学生信息管理系统
学生信息管理系统是针对学校人事处的大量业务处理工作而开发的管理软件,主要用于学校学生信息管理,总体任务是实现学生信息关系的系统化、科学化、规范化和自动化,其主要任务是用计算机对学生各种信息进行日常管理,如查询、修改、增加、删除,另外还考虑到学生选课,针对这些要求设计了学生信息管理系统。
基于SSM的学生信息管理系统
|
自然语言处理 编译器 C++
C++模板进阶知识
之前我们讲过模板初阶的知识,讲述了泛型编程、函数模板和一点类模板的知识,本篇我们将讲述一些进阶知识。
76 0
|
前端开发
渐变是真的好玩,真是一个有趣的特性
css 渐变是一种特殊的 image 格式,使用 gradient 表示, gradient 属于 image 的子集,用于表示渐变的 image , gradient 的语法如下
231 0
|
Python
你真的会调试你的python程序吗?
你真的会调试你的python程序吗?
233 0
你真的会调试你的python程序吗?
|
存储 网络协议 测试技术
命令行参数基本使用 | 学习笔记
快速学习命令行参数基本使用