杭电 1570 A C

Problem Description
Are you excited when you see the title "AC" ? If the answer is YES , AC it ;

You must learn these two combination formulas in the school . If you have forgotten it , see the picture.




Now I will give you n and m , and your task is to calculate the answer .
 

 

Input
In the first line , there is a integer T indicates the number of test cases.
Then T cases follows in the T lines.
Each case contains a character 'A' or 'C', two integers represent n and m. (1<=n,m<=10)
 

 

Output
For each case , if the character is 'A' , calculate A(m,n),and if the character is 'C' , calculate C(m,n).
And print the answer in a single line.
 

 

Sample Input
2 A 10 10 C 4 2
 

 

Sample Output
3628800 6
 

 

Author
linle
 

 

Source
 
    题目简述:给定两个值n、m,求这俩数的组合值和排列值!n,m的范围都很不大,所以这题不难!
 1 #include <stdio.h>
 2 
 3 int AA( int n, int m )
 4 {
 5     int mul = 1, i;
 6     for( i = 0; i <= (m-1); i++ )
 7         mul *= (n - i);
 8     return mul;
 9 }
10 
11 int main()
12 {
13     int tcase, n, m;
14     char c;
15     scanf( "%d", &tcase );
16     getchar();
17     while( tcase-- )
18     {
19             scanf( "%c %d %d", &c, &n, &m  );
20             getchar();
21             if( c == 'A' )
22                 printf( "%d\n", AA(n,m) );
23             else if( c == 'C' )
24                 printf( "%d\n",AA(n,m)/AA(m,m) );
25     }
26     return 0;
27 }
View Code

 

posted @ 2013-05-20 10:47  翼展zjz  阅读(164)  评论(0编辑  收藏  举报