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
#include<stdio.h> #include<string.h> int main() { char list[120],list2[120]; int T, n, i, j, len, len2, loc1, loc2, loc3, loc4, empty, flag; scanf("%d", &T); getchar(); while(T--) { loc1 = loc2 = loc3 = 0; loc4 = len = empty = 0; flag = 0; memset(list, '\0', sizeof(char)*120); memset(list2, '\0', sizeof(char)*120); fgets(list, 120, stdin); len = strlen(list) - 1; if(len == 4) {empty = 1;} else { if(list[0] == '<') {loc1 = 0; flag = 1;} for(i=0; i<len; ++i) { if(list[i] == '<' || list[i] == '>') { if(list[i] == '<') if(flag || loc1) loc3 = i; else loc1 = i; if(list[i] == '>') if(!loc2) loc2 = i; else loc4 = i; } } } fgets(list2, 120, stdin); len2 = strlen(list2)-1; if(!empty) { for(i=0; i<len; ++i) { if(list[i] != '<' && list[i] != '>') printf("%c", list[i]); } } printf("\n"); for(i=0; i<len2-3; ++i) printf("%c", list2[i]); if(!empty) { for(i=loc3+1; i<loc4; ++i) printf("%c", list[i]); for(i=loc2+1; i<loc3; ++i) printf("%c", list[i]); for(i=loc1+1; i<loc2; ++i) printf("%c", list[i]); for(i=loc4+1; i<len; ++i) printf("%c", list[i]); } printf("\n"); } return 0; }
解题报告:
根据题目意思,分割记录<>的位置,要考虑到第一行仅是<><>和第二行仅是...的可能,然后根据题目要求进行输出
WA——reason:
关乎到OJ的判题系统,而本题是Standard Input & Standard Ouput,用fgets时,在考虑最后一行输入时究竟有无换行符时,认为是由文件输入,此时并没有换行符
从而WA了一次,而看到题目标题才明白了!! WA第二次的时候我事先将第一行输出了,而题目明明要求是两行输入后两行输出啊。

更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?