Done:
/* Topcoder SRM 727, D1, 250-Pointer
OnlySanta
James S. Plank
Tue Sep 18 18:05:37 EDT 2018
*/
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
class OnlySanta {
public:
string solve(string S);
};
string OnlySanta::solve(string S)
{
int s, a, t;
string rv;
/* Find the first S. If there's no "S", then appending SANTA will work. */
s = S.find('S');
if (s == string::npos) return S + "SANTA";
/* Find the first A after the S.
If there's no subsequence "SA", then appending SANTA will work. */
a = S.find('A', s);
if (a == string::npos) return S + "SANTA";
/* Find the first T after the SA.
If there's no subsequence "SAT", then appending SANTA will work. */
t = S.find('T', a);
if (t == string::npos) return S + "SANTA";
/* Now that we've found the first "SAT" subsequence, put an "N" after the "A",
and an "A" at the end: */
rv = S.substr(0, a+1) + "N";
rv += S.substr(a+1);
rv += "A";
return rv;
}
|