标签:
题目链接:http://poj.org/problem?id=1572
输入数据时要注意,这里是string型
用getline(cin,origin[i]);
#include <string> #include <iostream> #include <algorithm> #include <stdio.h> using namespace std; const int maxn = 105; int n; string origin[maxn],rep[maxn],sequence; void init() { for(int i=0;i<n;i++) { getline(cin,origin[i]); getline(cin,rep[i]); } getline(cin,sequence); } void work() { int pos; int len; for(int i=0;i<n;i++) { pos=sequence.find(origin[i]); len=origin[i].length(); while(pos!=string::npos) { sequence.erase(pos,len); sequence.insert(pos,rep[i]); pos=sequence.find(origin[i]); } } cout<<sequence<<endl; } int main() { cin>>n; getchar(); while(n!=0) { init(); work(); cin>>n; getchar(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/TreeDream/p/5601474.html