PREV-1_蓝桥杯_核桃的数量

核桃分配问题
本文介绍了一个简单的编程问题——如何找出能够平均分配给三个不同大小团队的最小数量的核桃,通过一个C语言示例程序来解决这个问题。
问题描述

小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是:

1. 各组的核桃数量必须相同

2. 各组内必须能平分核桃(当然是不能打碎的)

3. 尽量提供满足1,2条件的最小数量(节约闹革命嘛)

输入格式
输入包含三个正整数a, b, c,表示每个组正在加班的人数,用空格分开(a,b,c<30)
输出格式
输出一个正整数,表示每袋核桃的数量。
样例输入1
2 4 5
样例输出1
20
样例输入2
 1 #include <stdio.h>
 2 
 3 int main(void)
 4 {
 5     int a,b,c,i;
 6     scanf("%d %d %d",&a,&b,&c);    
 7     for (i = 1 ; i; i ++)
 8     {
 9         if (i%a == 0 && i%b == 0 && i%c == 0)
10         {
11             printf("%d",i);
12             return 0;
13         }
14     }    
15     
16     return 0;
17 }

 

3 1 1
样例输出2
3
 
示例代码:
 

转载于:https://www.cnblogs.com/mind000761/p/8544697.html

static U1 u1_s_DspMnscrlLnkUpdt(const U4 * u4p_indctdbit, U1 u1_numcntt, ST_DMNSCRL_STCTL * stp_stctl, const ST_DMNSCRL_STCFG * stp_stcfg, U1 u1_tabactv) { const ST_DMNINTRPT * stp_intrpt; U4 u4_jdgintrpt; U1 u1_scrlend; U1 u1_rsult; U1 u1_jdglinkupdt; U1 u1_updtmd; U1 u1_intrptcntt; U1 u1_prev; U1 u1_next; stp_intrpt = stp_stcfg->stp_intrpt; u1_rsult = (U1)TRUE; u1_scrlend = stp_stctl->u1_scrlend; u1_jdglinkupdt = (U1)DMNSCRL_INTBKCALL; u1_intrptcntt = stp_intrpt->u1_intrptcntt; while((u1_intrptcntt < u1_numcntt ) &&(u1_rsult == (U1)TRUE)){ if((stp_stctl->st_link[u1_intrptcntt].sts.u1_prev < u1_numcntt) && (stp_stctl->st_link[u1_intrptcntt].sts.u1_next < u1_numcntt)){ u1_jdglinkupdt |= (U1)DMNSCRL_INTLINKD; } else if(stp_stctl->st_link[u1_intrptcntt].u2_cnttlink == (U2)DMNSCRL_UNLINKD){ u1_jdglinkupdt &= (U1)U1_MAX ^ (U1)DMNSCRL_INTLINKD; } else{ u1_rsult = (U1)FALSE; break; } if(u1_intrptcntt == stp_stctl->st_sts->sts.u1_dmncntt){ u1_jdglinkupdt |= (U1)DMNSCRL_INTCRRNT; } else{ u1_jdglinkupdt &= (U1)U1_MAX ^ (U1)DMNSCRL_INTCRRNT; } u4_jdgintrpt = u4p_indctdbit[stp_intrpt->u1_rqarrypos] & stp_intrpt->u4_rqbit; if(u4_jdgintrpt != (U4)0){ u1_jdglinkupdt |= (U1)DMNSCRL_INTINDCTD; } else{ u1_jdglinkupdt &= (U1)U1_MAX ^ (U1)DMNSCRL_INTINDCTD; } u1_jdglinkupdt &= (U1)DMNLNK_CNDMASK; u1_jdglinkupdt |= (U1)(stp_stcfg->stp_cnttinf[u1_intrptcntt].u1_attrbt << DMNLNK_CNDSHFT); u1_updtmd = u1_DMNSCRL_LNKUPDTMD[u1_jdglinkupdt]; switch(u1_updtmd){ case (U1)DMNLNK_NOP: break; case (U1)DMNLNK_RMV: u1_prev = stp_stctl->st_link[u1_intrptcntt].sts.u1_prev; u1_next = stp_stctl->st_link[u1_intrptcntt].sts.u1_next; stp_stctl->st_link[u1_prev].sts.u1_next = u1_next; stp_stctl->st_link[u1_next].sts.u1_prev = u1_prev; stp_stctl->st_link[u1_intrptcntt].u2_cnttlink = (U2)DMNSCRL_UNLINKD; break; case (U1)DMNLNK_RMVNXT: u1_prev = stp_stctl->st_link[u1_intrptcntt].sts.u1_prev; u1_next = stp_stctl->st_link[u1_intrptcntt].sts.u1_next; #if (__DMNSCRL_RMVNXTJMPFST_SUP__ == 1) stp_stctl->st_sts->sts.u1_dmncntt = stp_stctl->u1_scrlbegin; stp_stctl->st_sts->sts.u1_dmnopt = stp_stcfg->stp_cnttinf[stp_stctl->u1_scrlbegin].u1_defopt; #else stp_stctl->st_sts->sts.u1_dmncntt = u1_next; stp_stctl->st_sts->sts.u1_dmnopt = stp_stcfg->stp_cnttinf[u1_next].u1_defopt; #endif stp_stctl->st_link[u1_prev].sts.u1_next = u1_next; stp_stctl->st_link[u1_next].sts.u1_prev = u1_prev; stp_stctl->st_link[u1_intrptcntt].u2_cnttlink = (U2)DMNSCRL_UNLINKD; break; case (U1)DMNLNK_RMVNXT1ST: if(stp_stcfg->stp_cnttinf[stp_stctl->st_sts->sts.u1_dmncntt].fp_bkgnd != NULL){ stp_stctl->st_sts->u2_ctlsts = (stp_stcfg->stp_cnttinf[stp_stctl->st_sts->sts.u1_dmncntt].fp_bkgnd)(stp_stctl->st_sts->u2_ctlsts, (U1)DMNSCRL_BKGNDACT_INIT); } if(u1_tabactv == (U1)TRUE){ vd_DSPMNSCRL_LNKUPDTHOOK(); } u1_jdglinkupdt &= (U1)U1_MAX ^ (U1)DMNSCRL_INTBKCALL; u1_prev = stp_stctl->st_link[u1_intrptcntt].sts.u1_prev; u1_next = stp_stctl->st_link[u1_intrptcntt].sts.u1_next; #if (__DMNSCRL_RMVNXTJMPFST_SUP__ == 1) stp_stctl->st_sts->sts.u1_dmncntt = stp_stctl->u1_scrlbegin; stp_stctl->st_sts->sts.u1_dmnopt = stp_stcfg->stp_cnttinf[stp_stctl->u1_scrlbegin].u1_defopt; #else stp_stctl->st_sts->sts.u1_dmncntt = u1_next; stp_stctl->st_sts->sts.u1_dmnopt = stp_stcfg->stp_cnttinf[u1_next].u1_defopt; #endif stp_stctl->st_link[u1_prev].sts.u1_next = u1_next; stp_stctl->st_link[u1_next].sts.u1_prev = u1_prev; stp_stctl->st_link[u1_intrptcntt].u2_cnttlink = (U2)DMNSCRL_UNLINKD; break; case (U1)DMNLNK_INSAREA: u1_next = stp_stctl->st_link[u1_scrlend].sts.u1_next; if(u1_next < u1_numcntt){ stp_stctl->st_link[u1_intrptcntt].sts.u1_prev = u1_scrlend; stp_stctl->st_link[u1_intrptcntt].sts.u1_next = u1_next; stp_stctl->st_link[u1_scrlend].sts.u1_next = u1_intrptcntt; stp_stctl->st_link[u1_next].sts.u1_prev = u1_intrptcntt; u1_scrlend = u1_intrptcntt; } else{ u1_rsult = (U1)FALSE; /* error */ } break; case (U1)DMNLNK_UPDTLNKPT: u1_scrlend = u1_intrptcntt; break; case (U1)DMNLNK_INSFLXBL: u1_next = stp_stctl->st_sts->sts.u1_dmncntt; u1_prev = stp_stctl->st_link[u1_next].sts.u1_prev; if((u1_next < u1_numcntt) &&(u1_prev < u1_numcntt)){ stp_stctl->st_link[u1_prev].sts.u1_next = u1_intrptcntt; stp_stctl->st_link[u1_next].sts.u1_prev = u1_intrptcntt; stp_stctl->st_link[u1_intrptcntt].sts.u1_prev = u1_prev; stp_stctl->st_link[u1_intrptcntt].sts.u1_next = u1_next; #if (__DMNSCRL_INSFLXBLJMPCRRNT_SUP__ == 1) stp_stctl->st_sts->sts.u1_dmncntt = u1_intrptcntt; stp_stctl->st_sts->sts.u1_dmnopt = stp_stcfg->stp_cnttinf[u1_intrptcntt].u1_defopt; #endif } else{ u1_rsult = (U1)FALSE; } break; case (U1)DMNLNK_INSFLXBL1ST: #if (__DMNSCRL_INSFLXBLJMPCRRNT_SUP__ == 1) if(stp_stcfg->stp_cnttinf[stp_stctl->st_sts->sts.u1_dmncntt].fp_bkgnd != NULL){ stp_stctl->st_sts->u2_ctlsts = (stp_stcfg->stp_cnttinf[stp_stctl->st_sts->sts.u1_dmncntt].fp_bkgnd)(stp_stctl->st_sts->u2_ctlsts, (U1)DMNSCRL_BKGNDACT_INIT); } if(u1_tabactv == (U1)TRUE){ vd_DSPMNSCRL_LNKUPDTHOOK(); } #endif u1_jdglinkupdt &= (U1)U1_MAX ^ (U1)DMNSCRL_INTBKCALL; u1_next = stp_stctl->st_sts->sts.u1_dmncntt; u1_prev = stp_stctl->st_link[u1_next].sts.u1_prev; if((u1_next < u1_numcntt) &&(u1_prev < u1_numcntt)){ stp_stctl->st_link[u1_prev].sts.u1_next = u1_intrptcntt; stp_stctl->st_link[u1_next].sts.u1_prev = u1_intrptcntt; stp_stctl->st_link[u1_intrptcntt].sts.u1_prev = u1_prev; stp_stctl->st_link[u1_intrptcntt].sts.u1_next = u1_next; #if (__DMNSCRL_INSFLXBLJMPCRRNT_SUP__ == 1) stp_stctl->st_sts->sts.u1_dmncntt = u1_intrptcntt; stp_stctl->st_sts->sts.u1_dmnopt = stp_stcfg->stp_cnttinf[u1_intrptcntt].u1_defopt; #endif } else{ u1_rsult = (U1)FALSE; } break; default: u1_rsult = (U1)FALSE; /* error */ break; } stp_intrpt++; u1_intrptcntt = stp_intrpt->u1_intrptcntt; } return(u1_rsult); }结合刚才的u1_s_DspMnscrlDefLnkUpdt函数,逐行解释该代码,并给出该代码与u1_s_DspMnscrlDefLnkUpdt作用的区别
最新发布
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值