#include <iostream>
#include <vector>
#include <string>
#include<cstring>
#include<algorithm>
using namespace::std;
//包括遇到HTML entity時候要包起來
int main()
{
string s="123&TWD;432&JPY;";
string temp="";
vector<string> buffer;
int head =0;
int peak =0;
int tail=s.size()-1;
cout<<s<<endl;
while(head<tail){
if(s[head]==\'&\'){
peak=head;
++peak; //不存&
do{
temp+=s[peak];
++peak;
}while(s[peak]!=\';\');
temp+=s[peak];
buffer.push_back(temp);
s.replace(head+1,peak-head,"");
tail-=peak-head;
temp="";
}
if(s[tail]==\';\'){
peak=tail;
do{
temp+=s[peak];
--peak;
}while(s[peak]!=\'&\');
//不存& 所以沒有再一次temp+=s[peak];
reverse(temp.begin(),temp.end());
buffer.push_back(temp);
s.replace(peak+1,tail-peak,"");
tail=peak;
temp="";
}
swap(s[head],s[tail]);
head++;
tail--;
}
int last = buffer.size()-1;
for(int i=0;i<s.length();i++){
if(s[i]==\'&\'){
s.insert(i+1,buffer[last]);
last--;
}
}
cout<<s<<endl;
return 0;
}