uva 10115 - Automatic Editing

#include<iostream>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;

string pa[22];
string des;

int main(){
    int n;
    while(cin >> n && n != 0){
        cin.ignore();
        for(int i = 0; i < 2*n; i += 2){
            getline(cin,pa[i]);
            getline(cin,pa[i+1]);
        }
        getline(cin,des);

        for(int i = 0; i < 2*n; i += 2){
            int pos;
            while((pos = des.find(pa[i])) != string::npos){           //每次从头开始找
                des.replace(pos,pa[i].length(),pa[i+1]);
            }
        }
        cout << des << endl;
    }

    return 0;
}

 

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