Question 10361-Automatic Poetry

Source: Internet
Author: User

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 your ent 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 injection. 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 blks. 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, should t that instead of the three dots the string s4s3s2s5 shoshould 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

 

 


[Question ]:

Input:

Enter N groups of test cases. Each group has two strings.

First string format: s1 <s2> s3 <s4> s5


S1, s2, s3, s3, s4, and s5 can all be null, nonexistent, or all lowercase characters.

Second string format: s ....

Output:

Two strings are output for each test case.

First string format: s1s2s3s4s5

Second string format: ss4s3s2s5

[Code ]:


[Cpp]
*********************************
* Date:
* Author: SJF0115
* Question: Question 10361-Automatic Poetry
* Source:

* Result: AC
* Source: Ultraviolet
* Conclusion:
**********************************/
# Include <stdio. h>
# Include <string. h>
# Define N 110
Int main (){
Int I, j, Case, lena, lenb;
Char a [N], B [N], s [N], s1 [N], s2 [N], s3 [N], s4 [N], s5 [N];
// Freopen ("C: \ Users \ XIAOSI \ Desktop \ acm.txt", "r", stdin );
While (scanf ("% d \ n", & Case )! = EOF ){
While (Case --){
Gets ();
Gets (B );
Lena = strlen ();
// The first substring
For (j = 0, I = 0; a [I]! = '<'; I ++, j ++ ){
S1 [j] = a [I];
}
S1 [j] = '\ 0 ';
// Printf ("% s \ n", s1 );
// The second substring
For (I = I + 1, j = 0; a [I]! = '>'; I ++, j ++ ){
S2 [j] = a [I];
}
S2 [j] = '\ 0 ';
// Printf ("% s \ n", s2 );
// The third substring
For (I = I + 1, j = 0; a [I]! = '<'; I ++, j ++ ){
S3 [j] = a [I];
}
S3 [j] = '\ 0 ';
// Printf ("% s \ n", s3 );
// The fourth substring
For (I = I + 1, j = 0; a [I]! = '>'; I ++, j ++ ){
S4 [j] = a [I];
}
S4 [j] = '\ 0 ';
// Printf ("% s \ n", s4 );
// The Fifth substring
For (I = I + 1, j = 0; I <lena; I ++, j ++ ){
S5 [j] = a [I];
}
S5 [j] = '\ 0 ';
// Printf ("% s \ n", s5 );
// The second string
For (I = 0, j = 0; B [I]! = '.'; I ++, j ++ ){
S [j] = B [I];
}
S [j] = '\ 0 ';
// Printf ("% s \ n", s );
// Output
Printf ("% s \ n", s1, s2, s3, s4, s5 );
Printf ("% s \ n", s, s4, s3, s2, s5 );
}
}
Return 0;
}
 

/*********************************
* Date:
* Author: SJF0115
* Question: Question 10361-Automatic Poetry
* Source

* Result: AC
* Source: Ultraviolet
* Conclusion:
**********************************/
# Include <stdio. h>
# Include <string. h>
# Define N 110
Int main (){
Int I, j, Case, lena, lenb;
Char a [N], B [N], s [N], s1 [N], s2 [N], s3 [N], s4 [N], s5 [N];
// Freopen ("C: \ Users \ XIAOSI \ Desktop \ acm.txt", "r", stdin );
While (scanf ("% d \ n", & Case )! = EOF ){
While (Case --){
Gets ();
Gets (B );
Lena = strlen ();
// The first substring
For (j = 0, I = 0; a [I]! = '<'; I ++, j ++ ){
S1 [j] = a [I];
}
S1 [j] = '\ 0 ';
// Printf ("% s \ n", s1 );
// The second substring
For (I = I + 1, j = 0; a [I]! = '>'; I ++, j ++ ){
S2 [j] = a [I];
}
S2 [j] = '\ 0 ';
// Printf ("% s \ n", s2 );
// The third substring
For (I = I + 1, j = 0; a [I]! = '<'; I ++, j ++ ){
S3 [j] = a [I];
}
S3 [j] = '\ 0 ';
// Printf ("% s \ n", s3 );
// The fourth substring
For (I = I + 1, j = 0; a [I]! = '>'; I ++, j ++ ){
S4 [j] = a [I];
}
S4 [j] = '\ 0 ';
// Printf ("% s \ n", s4 );
// The Fifth substring
For (I = I + 1, j = 0; I <lena; I ++, j ++ ){
S5 [j] = a [I];
}
S5 [j] = '\ 0 ';
// Printf ("% s \ n", s5 );
// The second string
For (I = 0, j = 0; B [I]! = '.'; I ++, j ++ ){
S [j] = B [I];
}
S [j] = '\ 0 ';
// Printf ("% s \ n", s );
// Output
Printf ("% s \ n", s1, s2, s3, s4, s5 );
Printf ("% s \ n", s, s4, s3, s2, s5 );
}
}
Return 0;
}

 

 

 

[Cpp]
# Include <iostream>
# Include <string>
Using namespace std;
 
# Define maxn102
String a1, a2;
 
Void solve ()
{
Int p1 = a1.find ('<', 0 );
Int p2 = a1.find ('>', 0 );
Int p3 = a1.find ('<', p2 + 1 );
Int p4 = a1.find ('>', p2 + 1 );
String s1 = a1.substr (0, p1 );
String s2 = a1.substr (p1 + 1, p2-p1-1 );
String s3 = a1.substr (p2 + 1, p3-p2-1 );
String s4 = a1.substr (p3 + 1, p4-p3-1 );
String s5 = a1.substr (p4 + 1 );
Cout <s1 <s2 <s3 <s4 <s5 <endl;
A2.replace (a2.length ()-3, 3, s4 + s3 + s2 + s5 );
Cout <a2 <endl;
}
 
Int main ()
{
Int t; cin> t;
Cin. get ();
While (t --)
{
Getline (cin, a1 );
Getline (cin, a2 );
Solve ();
}
}

# Include <iostream>
# Include <string>
Using namespace std;

# Define maxn102
String a1, a2;

Void solve ()
{
Int p1 = a1.find ('<', 0 );
Int p2 = a1.find ('>', 0 );
Int p3 = a1.find ('<', p2 + 1 );
Int p4 = a1.find ('>', p2 + 1 );
String s1 = a1.substr (0, p1 );
String s2 = a1.substr (p1 + 1, p2-p1-1 );
String s3 = a1.substr (p2 + 1, p3-p2-1 );
String s4 = a1.substr (p3 + 1, p4-p3-1 );
String s5 = a1.substr (p4 + 1 );
Cout <s1 <s2 <s3 <s4 <s5 <endl;
A2.replace (a2.length ()-3, 3, s4 + s3 + s2 + s5 );
Cout <a2 <endl;
}

Int main ()
{
Int t; cin> t;
Cin. get ();
While (t --)
{
Getline (cin, a1 );
Getline (cin, a2 );
Solve ();
}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.