Find the number of strings formed using distinct characters of a given string | C ++ implementation of the approach ; Function to return the factorial of n ; Function to return the count of all possible strings that can be formed with the characters of the given string without repeating characters ; To store the distinct characters of the string str ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int fact ( int n ) { int fact = 1 ; for ( int i = 1 ; i <= n ; i ++ ) fact *= i ; return fact ; } int countStrings ( string str , int n ) { set < char > distinct_char ; for ( int i = 0 ; i < n ; i ++ ) { distinct_char . insert ( str [ i ] ) ; } return fact ( distinct_char . size ( ) ) ; } int main ( ) { string str = " geeksforgeeks " ; int n = str . length ( ) ; cout << countStrings ( str , n ) ; return 0 ; }