Skip to content

Instantly share code, notes, and snippets.

@goctave
Created April 20, 2012 05:41
Show Gist options
  • Save goctave/2426372 to your computer and use it in GitHub Desktop.
Save goctave/2426372 to your computer and use it in GitHub Desktop.
CareerCup_1.5@1point3acres
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
void replace(char *str)
{
int n = 0;
int i;
for(i = 0; str[i] != '\0'; i++)
if(str[i] == ' ')
n++;
if(n == 0)
return;
str = (char *)realloc(str, (i + 2 * n) * sizeof(char));
int j = i - 2, k = i + 2*n - 2;
while(j >= 0)
{
if(str[j] != ' ')
{
str[k] = str[j];
j--;
k--;
}
else
{
str[k--] = '0';
str[k--] = '2';
str[k--] = '%';
j--;
}
}
str[i + n - 1];
}
int main()
{
char *str = (char *)malloc(100 * sizeof(char));
fgets(str, 100, stdin);
replace(str);
printf("%s\n", str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment