Unique Alphabet Count

 Unique Alphabet Count 

PROBLEM STATEMENT :

A string S is passed as input to the program which has only alphabets (all alphabets in lower case). The program must print the unique count of alphabets in the string. 

Input Format: 

- The first line will contain the value of string S

Boundary Conditions: 

1 <= Length of S <= 100 

Output Format: 

The integer value representing the unique count of alphabets in the string S. 

Example Input/Output 1: 
Input: () 
level 
Output: 3

Explanation: 

The unique alphabets are l,e,v. Hence 3 is the output. 

Example Input/Output 2: 
Input: () 
manager 
Output: 6





                    

            1)    LEARN THRICE 

                                👇 

            2)    THINK TWICE

                                👇 

            3)    APPLY ONCE




SOLUTION :

C (Programming Language)


      

#include<stdio.h> #include<stdlib.h> int main() { int hash[256]={0},l,cnt=0,i; char s[101]; scanf("%s%n",s,&l); //%n calculates the length for(i=0;i<l;++i) { hash[s[i]]++; if(hash[s[i]]==1) cnt++; } printf("%d",cnt); }



C++ (CPP)

       

#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { string s; cin>>s; sort(s.begin(),s.end()); //Sort the string //unique arranges the unique characters in starting //of the same string and returns the ending address of //the unique characters int size=unique(s.begin(),s.end())-s.begin(); cout<<size; }



JAVA

       

import java.util.*; public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.next(); int[] hm=new int[256]; int cnt=0,i; for(i=0;i<s.length();++i) { hm[s.charAt(i)]++; if(hm[s.charAt(i)]==1) cnt++; } System.out.println(cnt); } }



PYTHON

       

s=input().strip() print(len(set(s)))



Never Stop Learning !!


Comments

Popular posts from this blog

DP (1) - Count number of ways to cover a distance

Zero Insert After K Times One

Left Number Twice Right