UVA10361 - Automatic Poetry(自动作诗机)
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.
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.
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
...
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<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; char s[100][1000],s1[200],s2[200]; int main() { int n; while(~scanf("%d%*c",&n)) { while(n--) { fgets(s1,sizeof(s1),stdin); //存回车 fgets(s2,sizeof(s2),stdin); //回车占一个位 int len=strlen(s1); int p=0,num=0; for(int i=0;i<len;i++) { s[p][num++]=s1[i]; if(s1[i]=='<'||s1[i]=='>') { s[p][num-1]='\0'; //为了提取每个<span id="transmark"></span>单词 p++; num=0; } else printf("%c",s1[i]); } s[p][num]='\0'; //回车在字符尾部 <span id="transmark"></span> s2[strlen(s2)-4]='\0'; //cout<<s2; printf("%s%s%s%s%s",s2,s[3],s[2],s[1],s[4]); } } }