码迷,mamicode.com
首页 > 其他好文 > 详细

A C

时间:2014-11-09 22:00:51      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   sp   for   

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.

bubuko.com,布布扣


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
 
 1 #include <stdio.h>
 2 
 3 int jieCheng(int number);
 4 
 5 int main(){
 6     int T;
 7     char c;
 8     int n;
 9     int m;
10     int n_jieCheng;
11     int m_jieCheng;
12     int n_m_jieCheng;
13     int result;
14     
15     scanf("%d",&T);
16     
17     while(T--){
18         getchar();
19         
20         scanf("%c%d%d",&c,&n,&m);
21         
22         n_jieCheng=jieCheng(n);
23         m_jieCheng=jieCheng(m);
24         n_m_jieCheng=jieCheng(n-m);
25         
26         if(c==A)
27             result=n_jieCheng/n_m_jieCheng;
28         
29         else
30             result=n_jieCheng/(m_jieCheng*n_m_jieCheng);
31             
32         printf("%d\n",result);
33     }
34     return 0;
35 }
36 
37 int jieCheng(int number){
38     int result;
39     int i;
40     
41     result=1;
42     
43     for(i=1;i<=number;i++)
44         result*=i;
45         
46     return result;
47 }

 

 

A C

标签:des   style   blog   http   io   color   ar   sp   for   

原文地址:http://www.cnblogs.com/zqxLonely/p/4085910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!