UVA 10361 (13.08.01)

来源:互联网 发布:ubuntu 没有fcitx 编辑:程序博客网 时间:2024/04/30 13:36

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

str

输出的格式是这样的:

s1s2s3s4s5(即去掉 < 和 >)

str s4s3s2s5(把几个字符串位置换一下接在str字符串后面)


做法: 采取模拟的思路, 数据量不大, 直接输入s1s2s3s4s5, 以遇到 < 或 > 作为间隔的标志~


AC代码:

#include<stdio.h>#include<string.h>int main() {char s1[111], s2[111], s3[111], s4[111], s5[111];char ch, str[111];int pos = 0;int T;int mark;scanf("%d%c", &T, &ch);while(T--) {pos = 0;ch = getchar();while(ch != '<' && ch != '\n') {s1[pos++] = ch;ch = getchar();}s1[pos] = '\0';pos = 0;ch = getchar();while(ch != '>' && ch != '\n') {s2[pos++] = ch;ch = getchar();}s2[pos] = '\0';pos = 0;ch = getchar();while(ch != '<' && ch != '\n') {s3[pos++] = ch;ch = getchar();}s3[pos] = '\0';pos = 0;ch = getchar();while(ch != '>' && ch != '\n') {s4[pos++] = ch;ch = getchar();}s4[pos] = '\0';pos = 0;ch = getchar();while(ch != '\n') {s5[pos++] = ch;ch = getchar();}s5[pos] = '\0';pos = 0;mark = 1;while(ch = getchar()) {str[pos++] = ch;if(str[pos-1] == '.' && str[pos-2] == '.' && str[pos-3] == '.') {str[pos-3] = '\0';break;}}ch = getchar();printf("%s%s%s%s%s\n", s1, s2, s3, s4, s5);printf("%s%s%s%s%s\n", str, s4, s3, s2, s5);}return 0;}