借书方案知多少

 

源码:

#include<iostream>
using namespace std;
int main()
{
int a,b,c,count=0;
for(a=1;a<=5;a++){
for(b=1;b<=5;b++)
{
for(c=1;c<=5;c++)
{

if(a!=b&&a!=c&&b!=c)
count++;
}
}
}cout<<count;
return 0;}

运行结果

60

 

优化:

#include<iostream>
using namespace std;
int main()
{
int a,b,c,count=0;
for(a=1;a<=5;a++){
for(b=1;b<=5;b++)
{
for(c=1;c<=5&&a!=b;c++)
{

if(a!=c&&b!=c)
count++;
}
}
}cout<<count;
return 0;}

posted @ 2023-04-15 11:48  jmhyyds  阅读(22)  评论(0)    收藏  举报