I M01 - Lex Characters Unique HackerRank answer

 Given a string consisting of lowercase english letters only, print all the unique characters in it in lexicographically increasing order.

Input Format

One string S.

Constraints

1 <= strlen(S) <= 1000

Output Format

One string consisting of the unique characters of string S in alphabetic order.

Sample Input 0

alohamora

Sample Output 0

ahlmor
Source Code
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    char str[1001];
        scanf("%s",str);
    int a[26]={0};
    int i=0;
    while(str[i])
    {
        a[str[i]-97]++;
        i++;
    }
    for(i=0;i<26;i++)
    {
        if(a[i]!=0)
            printf("%c",(i+97));
    }
    return 0;
}

Comments