Thursday 23 July 2015

FANCY



FANCY NUMBERS

Link to the question : FANCY 

HINT :

A very good question on permutation and combination. 
If we take for example the test case given in the question : 11112
The answer depends on the number of possible combinations of 1111 which satisfies the rules of the question.
Hence the number of combinations of 1111 is 2^3. As our combinations will depend on whether we choose a particular 1.

RECOMMENDED QUESTION :

After solving this pnc question, you may like solving this adhoc question .

SOURCE CODE :

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char a[50];
        int i,c,j;
        long long int ans=1;
        scanf("%s",a);
        i=0;
        j=strlen(a);

        while(i<j)
        {    c=0;

            while(a[i+1]==a[i])
            {
                c++;
                i++;
            }
            ans=ans * pow(2,c);
            i++;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
 

1 comment: