Problem I
Automatic Poetry
Input: standard input
Output: standardoutput
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 throughancient Egyptian pyramids, prehistoric caves and medival hallways. Now she isstanding in front of some important Germanic looking doorway and has to solve alinguistic riddle to pass. As usual, the riddle is not very intellectuallychallenging.
This time, the riddle involves poems containing a“Schuttelreim”. An example of a Schuttelreim is the following shortpoem:
Ein Kind halt seinen Schnabelnur,
wenn es hangt an derNabelschnur.
/*German contestants please forgive me. I had to modifysomething as they were not appearing correctly in plain text format*/
A Schuttelreim seems to be a typical German invention. Thefunny thing about this strange type of poetry is that if somebody gives you thefirst line and the beginning of the second one, you can complete the poemyourself. Well, even a computer can do that, and your task is to write aprogram which completes them automatically. This will help Lara concentrate onthe “action” part of Tomb Raider and not on the “intellectual”part.
Input
The input will begin with a line containing a singlenumber n. After this line follow n pairs of lines containing Schuttelreims. Thefirst line of each pair will be of the form
s1<s2>s3<s4>s5
where the si arepossibly empty, strings of lowercase characters or blanks. The second line willbe a string of lowercase characters or blanks ending with three dots“...”. Lines will we at most 100characters long.
Output
For each pair of Schuttelreim lines l1and l2 you are to output two lines c1 and c2in the following way: c1 is the same as l1 only that thebracket marks “<” and “>” are removed. Line c2is the same as l2 , except that instead ofthe three dots the string s4s3s2s5should 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
题目大意:对输入的第一行s1<s2>s3<s4>s5进行处理,输出s1s2s3s4s5。。对输入的第二行 进行s1s4s3s2s5处理。
解题思路: 对输出的处理: 开辟一个temp数组,对输入的字符串进行分块存储(< >为分块依据 ),分别找出s1 s2 s3 s4 s5 对应内容,然后按题母大意
输出。注意:用gets时,scnaf输入格式必须得加\n.
#include<stdio.h>
#include<iostream>
#include<string.h>
#define N 100
using namespace std;
int main()
{
int n;
char str[N], temp[5][N];
scanf("%d\n",&n);
while (n--){
memset(str,0,sizeof(str));
memset(temp,0,sizeof(temp));
int num, cnt = 0, k = 0;
gets(str);
num = strlen(str);
for (int i = 0; i < num; i++){
if (str[i] == '<'){
temp[cnt][k] == '\0';
cnt++;
k = 0;
}
else if (str[i] == '>'){
temp[cnt][k] == '\0';
cnt++;
k = 0;
}
else
temp[cnt][k++] = str[i];
}
gets(str);
cout << temp[0] << temp[1] << temp[2] << temp[3] << temp[4] << endl;
for (int j = 0; str[j] != '\0'; j++){
if (str[j] == '.' )
break;
else
putchar(str[j]);
}
cout << temp[3] << temp[2] << temp[1] << temp[4] <<endl;
}
return 0;
}