C语言猴子分香蕉

 时间:2026-05-07 05:35:11

1、打开Dev-C++

C语言猴子分香蕉

2、写好头函数

#include<stdio.h>

C语言猴子分香蕉

3、写好主函数

C语言猴子分香蕉

4、声明五个变量,one,two,three,four,five是每只猴子分成5堆后剩余的个数 ,使用穷举法,计算总共可能的数量

int temp,count,one,two,three,four,five;

//使用穷举法,count为香蕉总数,一个一个去尝试

//当one,two,three,four,five满足题目要求便输出count 

//假设数量最多只有100000个,输出的结果,取最小的正确结果 

for(count=1;count<=100000;count++)

{

    temp=count;

    one=temp%5;

    temp=temp-temp/5-one;

    two=temp%5;

    temp=temp-temp/5-two;

    three=temp%5;

    temp=temp-temp/5-three;

    four=temp%5;

    temp=temp-temp/5-four;

    five=temp%5;

    //若one,two,three,four,five满足题目要求便输出 

    if(one==1 && two==2 && three==3 && four==4 && five==0)

    {

         printf("%d\n",count);

    }

}

C语言猴子分香蕉

5、总体代码

#include<stdio.h>

void main()

{

     //one,two,three,four,five是每只猴子分成5堆后剩余的个数 

     int temp,count,one,two,three,four,five;

     //使用穷举法,count为香蕉总数,一个一个去尝试

    //当one,two,three,four,five满足题目要求便输出count 

    //假设数量最多只有100000个,输出的结果,取最小的正确结果 

    for(count=1;count<=100000;count++)

    {

         temp=count;

         one=temp%5;

         temp=temp-temp/5-one;

        two=temp%5;

        temp=temp-temp/5-two;

        three=temp%5;

        temp=temp-temp/5-three;

        four=temp%5;

        temp=temp-temp/5-four;

        five=temp%5;

        //若one,two,three,four,five满足题目要求便输出 

        if(one==1 && two==2 && three==3 && four==4 && five==0)

       {

            printf("%d\n",count);

        }

    }

} 

C语言猴子分香蕉

6、结果如下图

C语言猴子分香蕉

  • 已知空间两点(4,-3,0),(3,1,-2),怎么求空间直线方程
  • 如何用Python统计文本点击量统计
  • 设计模式:C#如何实现单例模式
  • Python如何将姓名和密码存入字典
  • html基础操作,制作静态网页
  • 热门搜索
    吃什么可以补气血 打嗝怎么办怎么止嗝 永康旅游 太原旅游攻略景点必去 邢帅教育怎么样 烬的大招怎么放 cf分辨率怎么调 衣服上的血迹怎么洗 回收站清空的文件怎么恢复 怎么双飞