一个借书方案(运用排列)
2007-10-29 16:46
288 查看
如果A有N本书,我们要将这N本书分给三个人,有多少中分法。
程序实现如下:
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace Test
6 {
7 class Program
8 {
9 static void Main(string[] args)
{
int a, b, c, d, count = 0;
Console.Write("How many books:");
d = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("There are different methods for XM to distribute books to 3 Readers:");
for (a = 1; a <= d; a++)
for (b = 1; b <= d; b++)
for (c = 1; a != b && c <= d; c++)
if (c != a && c != b)
Console.WriteLine("{0}: {1},{2},{3}", ++count, a, b, c);
}
}
}
程序实现如下:
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace Test
6 {
7 class Program
8 {
9 static void Main(string[] args)
{
int a, b, c, d, count = 0;
Console.Write("How many books:");
d = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("There are different methods for XM to distribute books to 3 Readers:");
for (a = 1; a <= d; a++)
for (b = 1; b <= d; b++)
for (c = 1; a != b && c <= d; c++)
if (c != a && c != b)
Console.WriteLine("{0}: {1},{2},{3}", ++count, a, b, c);
}
}
}
相关文章推荐
- 写一个函数输出一个字符串中的所有排列
- 一个简单的日志采集方案
- 臆想了一个方案---全民医疗
- 程序员面试金典: 9.4树与图 4.3给定一个有序整数数组,元素各不相同且按升序排列,创建一颗高度最小的二叉查找树。 ---快速解法
- js 排列 组合 的一个简单例子
- 短信防刷的一个小方案
- C语言 编写一个函数,将参数字符串中的字符反向排列。要求:不能使用C函数库中的字符串操作函数,
- 运用UE和Blocks,仅用两周打造一个VR游戏(52VR完整版译文)
- 解决些重复性工作---对GridView的一个扩展方案
- 怎么做一个没有大坑的项目方案
- 逆波兰式的学习、运用(附带C++写的一个整数的计算器)
- 终于弄用了,一个可拖拽(移动)、编辑、锁定和关闭的div层,自动排列
- 一个较为详细的ETL系统实现方案
- 运用C#创建一个.Net下的Web Service
- 一个基于Prism的方案的介绍
- 一个链表L 一个链表P 包含升序排列的整数 操作PrintLots(L,P)将打印L中那些由P所指定的位置上的元素
- 一个支持socket并发的方案
- 写正确函数需要注意的地方:输入一个字符串,打印出该字符串中字符的所有排列
- 一个Form验证的方案
- web开发中解决一个浏览器登录多个用户的方案