zoukankan      html  css  js  c++  java
  • sicily 6271. 借书

    Description

      小明有n本新书,要借给3位小朋友,假设每人每次只能借一本。小明想知道一共有多少种不同的借法,聪明的你需要写个程序来帮忙小明,输出一共有多少种借法,并输出这些借法,按照字典序排序。

    Input

     输入多个case

    每个case如下:

    输入n

    其中 10 > n >= 3

    Output

     对于每个case,

    第一行,输出借法的个数;

    接着每一行输出一种借法。

    一开始没看懂题目什么意思,琢磨半天明白了,就是把ABCD....J这十个字母按字典顺序进行排列。

    用了实验作业里写的函数,在处理字母的问题上用ASCII码与数字的对应处理,一次AC

    View Code
     1 // Problem#: 6271
     2 // Submission#: 1602395
     3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
     4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
     5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University
     6 #include<stdio.h>
     7 int perm( int m, int n );
     8 int main()
     9 {
    10     int A, B, C, x;
    11     while( scanf("%d", &x ) != EOF )
    12     {
    13         printf("%d\n", perm(x,3) );
    14     for ( A = 65; A <= 64+x; A++ )
    15     {
    16         for ( B = 65; B <= 64+x; B++ )
    17         {
    18             for ( C = 65; C <= 64+x; C++ )
    19             {
    20                 if ( A != B && B != C && A != C )
    21                 printf("%c%c%c\n", A, B, C);
    22             }
    23         }
    24     }
    25     }
    26     return 0;
    27     }
    28 
    29 int perm( int m, int n )
    30 {
    31     int facto1 = 1;
    32     int facto2 = 1;
    33     int i;
    34     
    35     for ( i = 1; i <= m; i++ )
    36     {
    37         facto1 = facto1 * i;
    38     }
    39     
    40     for ( i = 1; i <= (m - n); i++ )
    41     {
    42         facto2 = facto2 * i;
    43     }
    44     
    45     return  ( facto1 / facto2 );
    46 }                                 
  • 相关阅读:
    移动端 h5开发相关内容总结——CSS篇
    水滴导航特效
    腾讯课堂之前端开发html5css3javascriptjQueryJS年薪20万
    阿里前端笔试总结
    Web 开发的未来:React、Falcor 和 ES6
    Yii2按需加载图片怎么做?
    Yii2 灵活加载js、css
    Ubuntu上搭建SVN
    yii pageTitle与Yii::app()->name的区别
    Mysql--Database Exception (#42) 数据库错误
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2750452.html
Copyright © 2011-2022 走看看