Skip to content

Instantly share code, notes, and snippets.

@itsPG
Created March 11, 2013 21:01
Show Gist options
  • Save itsPG/5137709 to your computer and use it in GitHub Desktop.
Save itsPG/5137709 to your computer and use it in GitHub Desktop.
/*
ACM 11988 by PG, All rights reserved
*/
#include "stdio.h"
#include "stdlib.h"
int main()
{
char q[100001];
int home[100001];
int end[100001];
int i,j;
while (gets(q))
{
int home_m = 0, end_m = 0;
int len = strlen(q);
home[home_m++] = 0;
for (i = 0; i < len; i++)
{
if (q[i] == '[') home[home_m++] = i + 1;
else if (q[i] == ']') end[end_m++] = i + 1;
}
for (i = home_m - 1; i >= 0; i--)
{
for (j = home[i]; j < len && q[j] != '[' && q[j] != ']'; j++) printf("%c", q[j]);
}
for (i = 0; i < end_m ; i++)
{
for (j = end[i]; j < len && q[j] != '[' && q[j] != ']'; j++) printf("%c", q[j]);
}
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment