UVa : 10338



import java.math.BigInteger;
import java.util.Scanner;

/**
 *
 * @author Shahab
 */
public class Main {

      public static void main(String[] args) {
            // TODO code application logic here
            Scanner input = new Scanner (System.in);

            int dataSet = input.nextInt();
            int cases = 0;

            while ( dataSet-- != 0 ) {
                  String str = input.next();

                  int frq [] = new int [26];
                  BigInteger num = BigInteger.ONE;

                  for ( int i = 0; i < str.length(); i++ ) {
                        frq [str.charAt(i) - 'A']++;
                        num = num.multiply(BigInteger.valueOf(i + 1));
                  }

                  BigInteger denom = BigInteger.ONE;

                  for ( int i = 0; i < 26; i++ ) {
                        for ( int j = 1; j <= frq [i]; j++ )
                              denom = denom.multiply(BigInteger.valueOf(j));
                  }

                  System.out.printf ("Data set %d: ", ++cases);
                  System.out.println (num.divide(denom));
            }

      }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s