程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVA 題目10361 - Automatic Poetry

UVA 題目10361 - Automatic Poetry

編輯:C++入門知識

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 ancient 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 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.

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 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.

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 , except that instead of the three dots the string s4s3s2s5 should 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

 

 


【題意】:

輸入:

輸入N組測試用例,每組輸入兩個字符串。

第一個字符串格式:s1<s2>s3<s4>s5


s1,s2,s3,s3,s4,s5都可以為空或者不存在或者全是小寫字符

第二個字符串格式:s ....

輸出:

每組測試用例輸出兩個字符串。

第一個字符串格式:s1s2s3s4s5

第二個字符串格式:ss4s3s2s5

【代碼】:


[cpp]
*********************************
*   日期:2013-4-26
*   作者:SJF0115
*   題號: 題目10361 - Automatic Poetry
*   來源:

*   結果:AC
*   來源:UVA
*   總結:
**********************************/ 
#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(a); 
            gets(b); 
            lena = strlen(a); 
            //第一個子串  
            for(j = 0,i = 0;a[i] != '<';i++,j++){ 
                s1[j] = a[i]; 
            } 
            s1[j] = '\0'; 
            //printf("%s\n",s1);  
            //第二個子串  
            for(i = i+1,j = 0;a[i] != '>';i++,j++){ 
                s2[j] = a[i]; 
            } 
            s2[j] = '\0'; 
            //printf("%s\n",s2);  
            //第三個子串  
            for(i = i+1,j = 0;a[i] != '<';i++,j++){ 
                s3[j] = a[i]; 
            } 
            s3[j] = '\0'; 
            //printf("%s\n",s3);  
            //第四個子串  
            for(i = i+1,j = 0;a[i] != '>';i++,j++){ 
                s4[j] = a[i]; 
            } 
            s4[j] = '\0'; 
            //printf("%s\n",s4);  
            //第五個子串  
            for(i = i+1,j = 0;i < lena;i++,j++){ 
                s5[j] = a[i]; 
            } 
            s5[j] = '\0'; 
            //printf("%s\n",s5);  
            //第二個字符串  
            for(i = 0,j = 0;b[i] != '.';i++,j++){ 
                s[j] = b[i]; 
            } 
            s[j] = '\0'; 
            //printf("%s\n",s);  
            //輸出  
            printf("%s%s%s%s%s\n",s1,s2,s3,s4,s5); 
            printf("%s%s%s%s%s\n",s,s4,s3,s2,s5); 
        } 
    } 
    return 0; 

 
     

/*********************************
*   日期:2013-4-26
*   作者:SJF0115
*   題號: 題目10361 - Automatic Poetry
*   來源

*   結果:AC
*   來源:UVA
*   總結:
**********************************/
#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(a);
   gets(b);
   lena = strlen(a);
   //第一個子串
   for(j = 0,i = 0;a[i] != '<';i++,j++){
    s1[j] = a[i];
   }
   s1[j] = '\0';
   //printf("%s\n",s1);
   //第二個子串
   for(i = i+1,j = 0;a[i] != '>';i++,j++){
    s2[j] = a[i];
   }
   s2[j] = '\0';
   //printf("%s\n",s2);
   //第三個子串
   for(i = i+1,j = 0;a[i] != '<';i++,j++){
    s3[j] = a[i];
   }
   s3[j] = '\0';
   //printf("%s\n",s3);
   //第四個子串
   for(i = i+1,j = 0;a[i] != '>';i++,j++){
    s4[j] = a[i];
   }
   s4[j] = '\0';
   //printf("%s\n",s4);
   //第五個子串
   for(i = i+1,j = 0;i < lena;i++,j++){
    s5[j] = a[i];
   }
   s5[j] = '\0';
   //printf("%s\n",s5);
   //第二個字符串
   for(i = 0,j = 0;b[i] != '.';i++,j++){
    s[j] = b[i];
   }
   s[j] = '\0';
   //printf("%s\n",s);
   //輸出
   printf("%s%s%s%s%s\n",s1,s2,s3,s4,s5);
   printf("%s%s%s%s%s\n",s,s4,s3,s2,s5);
  }
 }
 return 0;
}

 

 

 

[cpp]
#include<iostream>  
#include<string>  
using namespace std; 
 
#define MAXN 102  
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 MAXN 102
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();
    }
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved