您的位置:首页 > 其它

c程序基本算法百例之八—借书方案知多少

2011-05-15 16:06 323 查看
#include"stdio.h"
int
main()
{
int a,b,c,count=0;
printf("借书方案为:/n");
for(a=1;a<=5;a++)
for(b=1;b<=5;b++)
for(c=1;a!=b&&c<=5;c++)
if(c!=a&&c!=b)
printf(count%5?"%2d:%d,%d,%d   ":"%2d:%d,%d,%d/n",++count,a,b,c);// ?"":为若为真则实行前者,为假执行后者
return 0;
}
/*
output:
--------------------------------------------------------------------------------------
借书方案为:
1:1,2,3    2:1,2,4    3:1,2,5    4:1,3,2    5:1,3,4
6:1,3,5    7:1,4,2    8:1,4,3    9:1,4,5   10:1,5,2
11:1,5,3   12:1,5,4   13:2,1,3   14:2,1,4   15:2,1,5
16:2,3,1   17:2,3,4   18:2,3,5   19:2,4,1   20:2,4,3
21:2,4,5   22:2,5,1   23:2,5,3   24:2,5,4   25:3,1,2
26:3,1,4   27:3,1,5   28:3,2,1   29:3,2,4   30:3,2,5
31:3,4,1   32:3,4,2   33:3,4,5   34:3,5,1   35:3,5,2
36:3,5,4   37:4,1,2   38:4,1,3   39:4,1,5   40:4,2,1
41:4,2,3   42:4,2,5   43:4,3,1   44:4,3,2   45:4,3,5
46:4,5,1   47:4,5,2   48:4,5,3   49:5,1,2   50:5,1,3
51:5,1,4   52:5,2,1   53:5,2,3   54:5,2,4   55:5,3,1
56:5,3,2   57:5,3,4   58:5,4,1   59:5,4,2   60:5,4,3
Process returned 0 (0x0)   execution time : 0.312 s
Press any key to continue.
---------------------------------------------------------------------------------------
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: