Skip to content

Instantly share code, notes, and snippets.

@goctave
Created April 18, 2012 01:38
Show Gist options
  • Save goctave/2410435 to your computer and use it in GitHub Desktop.
Save goctave/2410435 to your computer and use it in GitHub Desktop.
CareerCup 1.3
/************************************
O(n^2)的算法
*************************************/
#include <stdio.h>
#include <string.h>
void unique(char str[])
{
int len = strlen(str);
int i, j;
for(i = 0, j = 0; i < len; i++)
{
int k = 0;
int flag = 0;
while(k <= j)
{
if(str[k] == str[i])
{
flag = 1;
break;
}
else
k++;
}
if(flag)
continue;
str[++j] = str[i];
}
str[++j] = '\0';
}
int main()
{
char str[100];
scanf("%s", str);
unique(str);
printf("%s\n", str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment