Skip to content

Instantly share code, notes, and snippets.

@evilmucedin
Created August 30, 2016 10:46
Show Gist options
  • Save evilmucedin/de78731a8096236f4198ca0de1981577 to your computer and use it in GitHub Desktop.
Save evilmucedin/de78731a8096236f4198ca0de1981577 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
static string InjectSpaces(const string& s) {
string result(2*s.length() - 1, ' ');
char* pResult = (char*)result.data();
const char* pS = s.data();
const auto length = s.length();
for (auto i = 0; i < length; ++i) {
pResult[2*i] = pS[i];
}
return result;
}
int main() {
string s = "1234567890";
string result;
for (size_t i = 0; i < 200000000; ++i) {
result = InjectSpaces(s);
}
cout << result << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment