Problem Statement:
Logesh is a unique guy! He always finds geeky stuff in his way around. He is happy today being gifted with a baby boy. Now its time for him to think of a name. But he don’t want to spend time in banging his head. He took a lucky string and considering two lucky indices X and Y. The characters at X and Y are interchangeable and the remaining can be shuffled with their positions ending up in different names. Help him to find the number of different possible names given the lucky string and the lucky positions X and Y.
(Assume index starts with 0)
INPUT
The first input T, should be the number of test cases. Strings S, position X , position Y are given in the next T lines.
(String contains either all uppercase or all lowercase alphabets)
OUTPUT
For each test case, output the total number of different possible names
CONSTRAINTS
1 <= T <= 5
2<=String length <= 100
SAMPLE INPUT
2
alice 2 4
anand 1 3
SAMPLE OUTPUT
12
3
here is my code in C
fact(int n){
if(n==0)
return 1;
if(n>1)
n=n*fact(n-1);
return n;
}
main()
{
int T;
scanf("%d",&T);
while(T--)
{
char str[100],ch;
int pos,pos1,i,hash[26]={0},count=0;
scanf("%s %d %d",str,&pos,&pos1);
if(str[0]>='a' && str[0]<='z')
ch='a';
else
ch='A';
for(i=0;str[i];i++)
{
if(!hash[str[i]-ch] && pos!=i && pos1!=i)
count++;
hash[str[i]-ch]++;
}
if(str[pos]!=str[pos1])
printf("%d\n",2*fact(count));
else if(pos==pos1)
printf("%d\n",fact(count));
else
printf("%d\n",fact(count)+1);
}
return 0;
}