Advertisement
Shailrshah

Number of Anagrams of a lowercase String

Dec 22nd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     static int  factorial(int n){
  4.         int fact = 1;
  5.         while(n>1) fact *= n--;
  6.         return fact;
  7.     }
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.         String str = sc.next();
  11.         int i,  length = str.length();
  12.         int[] a = new int[26];
  13.         for(i = 0; i < length; i++) a[str.charAt(i)-97]++;  // 'a'=97
  14.         int den = 1;
  15.         for(i = 0; i < 26; i++) den *= factorial(a[i]);
  16.         System.out.println(factorial(length)/den);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement