Monday, 26 November 2012

UNIQUE CHAR IN STRING

Q.) FIND UNIQUE CHAR IN  A GIVEN STRING.

SOLUTION---


#include
#include
int main()
{
    char str[400];
    scanf("%s",str);
    int i,d,len;
    len=strlen(str);
    int arr[128];
    for(i=0;i<128;i++)
        arr[i]=0;
    for(i=0;i<len;i++)
    {
        d=str[i];
        arr[d]+=1;
    }
    for(i=0;i<len;i++)
    {
        d=str[i];
        if(arr[d]==1){
            printf("%c ->unique char in string",str[i]);
           
        }
    }
    return 0;
}

3 comments:

rajpal singh said...

remove break statement else if there are more than one unique characters in string, program will not print them.it will only print the first unique char

CHANDAN SINGH said...

thnxx @rajpal sir :)

Anonymous said...

can you plz implement and explain longest increasing subsequence...