Friday, June 02, 2017

Tomi miah's probablity

Cpbook.subeen.com

problem:19

Tomi miah's probablity





Solution: 

#include<cstdio>
#include<iostream>
#include<map>
#include<vector>

using namespace std;
map<string,long long int>mp;
long long int fact(long long int a)
{
    if(a==0) return 1;
    return a*fact(a-1);
}
int main()
{
    long long int t;
    scanf("%lld\n",&t);
    while(t--)
    {
        vector<string>vc;
        string str,s;
        long long int a=1,u=0,cnt=0;
        getline(cin,str);
        for(int i=0; i<str.size(); i++)
            if(i==str.size()-1||str[i]==' ')
            {
                s="";
                for(int j=u; j<i; j++) s+=str[j];
                if(i==str.size()-1) s+=str[i];
                u=i+1;
                mp[s]++;
                if(mp[s]==1) vc.push_back(s);
                cnt++;
            }
        for(int j=0; j<vc.size(); j++) a*=fact(mp[vc[j]]);
        a=fact(cnt)/a;
        printf("1/%lld\n",a);
        for(int j=0; j<vc.size(); j++) mp[vc[j]]=0;
    }
    return 0;
}
//Language:C++

No comments:

Post a Comment