10361-automatic poetry
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem &problem=1302
"Oh God", Lara Croft exclaims, "It's one of these dumb riddles again!"
In Tomb raider XIV, Lara are, as ever, gunning her way through ancient Egyptian pyramids, prehistoric caves and Medival HAL Lways. Now she's 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 are 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 no appearing correctly in plain text format*/
A Schuttelreim seems to be a typical German invention. The funny thing about this strange type of poetry are that if somebody gives for you the "the" and the beginning of the The SE Cond one, you can complete the poem yourself. So, even a computer can do that, and your task are to write a program which completes them. This would help Lara concentrate on the ' action ' part of Tomb raider and is ' intellectual ' part.
Input
The input would begin with a line containing a single number n. After this line follow n pairs of lines containing schuttelreims. The ' a ' of each pair'll be the form
S1<s2>s3<s4>s5
Where the Si are possibly empty, strings of lowercase characters or blanks. The second line is a string of lowercase characters or blanks ending with three dots "...". Lines'll we at most 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 a s L1 only to that bracket marks "<" and ">" are removed. Line C2 are 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
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
Complete code: (C style)
/*0.019s*/
#include <cstdio>
#include <cstring>
char s[7][100];
inline void Partgets (char *str, char ch)
{
int i;
char c;
for (i = 0; (c = GetChar ())!= ch; ++i)
str[i] = c;
Str[i] = ' the '; Don't forget to manually add the
"
int" main (void)
{
int t;
scanf ("%d\n", &t);
while (t--)
{
partgets (s[1], ' < ');
Partgets (s[2], ' > ');
Partgets (s[3], ' < ');
Partgets (s[4], ' > ');
Partgets (s[5], ' \ n ');
Gets (S[6]);
S[6][strlen (S[6])-3] = ';
printf ("%s%s%s%s%s\n", S[1], s[2], s[3], s[4], s[5]);
printf ("%s%s%s%s%s\n", S[6], s[4], s[3], s[2], s[5);
return 0;
}
C + + Style:
/*0.016s*/
#include <cstdio>
#include <iostream>
using namespace std;
String s1, S2, S3, S4, S5, S6;
int main (void)
{
int t;
scanf ("%d\n", &t);
while (t--)
{
getline (cin, S1, ' < ');
Getline (CIN, S2, ' > ');
Getline (CIN, S3, ' < ');
Getline (CIN, S4, ' > ');
Getline (CIN, S5);
Getline (CIN, S6);
S6.erase (S6.end ()-3, S6.end ()); Remove the end "..."
cout << s1 << S2 << S3 << S4 << S5 << Endl;
cout << S6 << S4 << S3 << S2 << S5 << Endl;
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/