uva 10361 - Automatic Poetry

来源:互联网 发布:python输入ctrl c 编辑:程序博客网 时间:2024/06/05 14:16

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 riddlesagain!”

 

In Tomb Raider XIV, Lara is, as ever, gunning her way throughancient Egyptian pyramids, prehistoric caves and medival hallways.Now she is standing in front of some important Germanic lookingdoorway and has to solve a linguistic riddle to pass. As usual, theriddle is not very intellectually challenging.

 

This time, the riddle involves poems containing a“Schuttelreim”. An example of a Schuttelreim is the following shortpoem:

 

Ein Kind halt seinen Schnabel nur,

wenn es hangt an derNabelschnur.        

 

 

A Schuttelreim seems to be a typical German invention. The funnything about this strange type of poetry is that if somebody givesyou the first line and the beginning of the second one, you cancomplete the poem yourself. Well, even a computer can do that, andyour task is to write a program which completes them automatically.This will help Lara concentrate on the “action” part of Tomb Raiderand 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 lowercasecharacters or blanks. The second line will be a string of lowercasecharacters or blanks ending with three dots “...”. Lines will we atmost 100 characters long.

Output

For each pair of Schuttelreim lines l1 andl2 you are to output two lines c1 andc2 in the following way: c1 is the same asl1 only that the bracket marks “<” and“>” are removed. Line c2 is the same asl2 , except that instead of the three dots the strings4s3s2s5 shouldappear.

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

 

 

代码:

#include<stdio.h>
#include<string.h>
int main()
 {
    inti,len1,len2,cases,num,s1,s2,s3,s4;
 char line1[101],line2[101];
 scanf("%d",&cases);getchar();//getchar();
   while(cases--)
    {
  gets(line1);
  gets(line2);
 // puts(line1);printf("%dline1\n",cases);
 // puts(line2);printf("%d line2\n",cases);
  len1=strlen(line1);
  num=1;
  for(i=0;i<len1;i++)
  {
   if(line1[i]=='<'|| line1[i]=='>')
   {
    if(num==1)s1=i;
    if(num==2)s2=i;
    if(num==3)s3=i;
    if(num==4)s4=i;   
    num++;
   }
   elseprintf("%c",line1[i]);
  }
  printf("\n");
  len2=strlen(line2);
  for(i=0;i<len2;i++)
  {
   if(line2[i]=='.')break;
   elseprintf("%c",line2[i]);
  }
  for(i=s3+1;i<s4;i++)printf("%c",line1[i]);
  for(i=s2+1;i<s3;i++)printf("%c",line1[i]);
  for(i=s1+1;i<s2;i++)printf("%c",line1[i]);
  for(i=s4+1;i<len1;i++)printf("%c",line1[i]);
  printf("\n");
 }
    return0;
}