问:“we;tonight:you” --> "ew;thginot;uoy"
答:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string func(const string& s,const char c)
{
unsigned int head = 0;
unsigned int pos = 0;
string ret , ssub;
while((pos=s.find(c,head))!=string::npos)
{
ssub = s.substr(head,pos-head+1);
reverse(ssub.begin(),ssub.end()-1);
ret += ssub ;
head = pos+1;
}
if(head<s.length())
{
ssub = s.substr(head,s.length()-head+1);
reverse(ssub.begin(),ssub.end());
ret += ssub;
}
return ret;
}
int main()
{
string input,output;
cin >> input;
output = func(input,';');
cout << output << endl;
return 0;
}