Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues
Created July 30, 2016 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigRodrigues/3d0482f6167cf8a1fe1a7d85314aca53 to your computer and use it in GitHub Desktop.
Save CraigRodrigues/3d0482f6167cf8a1fe1a7d85314aca53 to your computer and use it in GitHub Desktop.
CS50x Coding Contest 2016 - Name Your Cat
#include <stdio.h>
#include <string.h>
#include "cs50.h"
int main(void)
{
int n = GetInt();
string s = GetString();
int i = 0;
int j = 1;
while (i < (n-j))
{
if (s[i] == 'a' || s[i] == 'c' || s[i] == 'e' || s[i] == 'i' || s[i] == 'k' || s[i] == 'n' || s[i] == 't')
{
if (s[n-j] == 'a' || s[n-j] == 'c' || s[n-j] == 'e' || s[n-j] == 'i' || s[n-j] == 'k' || s[n-j] == 'n' || s[n-j] == 't')
{
//swap
char temp = s[i];
s[i] = s[n-j];
s[n-j] = temp;
i++;
j++;
}
else
{
//incrememnt j if we don't swap to find next viable char
j++;
}
}
else
i++;
}
printf("%s", s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment