uva 10361 - Automatic Poetry

#include<iostream>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;

char str1[105],str2[105];
string s2,s4;


int main(){
    int n;
    cin >> n;
    getchar();
    while(n--){
        gets(str1);
        gets(str2);
        s2 = "";
        s4 = "";
        int cnt = 0;
        int pos1,pos2;
        for(int i = 0; i < strlen(str1); i++)
        {
            int j;
            if(str1[i] == '<'){
                if(!cnt){
                    for(j = i+1; str1[j] != '>'; j++)
                    s2 += str1[j];                   //求s2
                    pos1 = j + 1;                    //记录s3起始位置
                    cnt ++;
                }else{
                    for(j = i+1; str1[j] != '>'; j++)
                        s4 += str1[j];              //求s4
                    pos2 = j + 1;                    //记录s4起始位置
                }
            }
            if(!(str1[i] == '<' || str1[i] == '>'))
                cout << str1[i];
        }
        cout << endl;

        for(int i = 0; i< strlen(str2) - 3; i++)
            cout << str2[i];
        cout << s4;
        for(int i = pos1; str1[i] != '<';i++)
            cout << str1[i];
        cout << s2;
        for(int i = pos2; str1[i] != '\0';i++)
            cout << str1[i];
        cout << endl;
    }

    return 0;
}

 

posted @ 2015-07-16 10:10  杨永华  阅读(146)  评论(0编辑  收藏  举报