首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >百钱买白鸡 C C++ Python

百钱买白鸡 C C++ Python

作者头像
叶茂林
发布于 2023-07-28 20:22:19
发布于 2023-07-28 20:22:19
3280
举报

C

代码语言:javascript
复制
#include <stdio.h>
int main()
{
	int cock,hen;
	for(cock=0;cock<=20;cock++)
	for(hen=0;hen<=33;hen++)
	if(5*cock+3*hen+(100-cock-hen)*1.0/3==100)
	printf("cock=%d hen=%d chick=%d\n",cock,hen,100-cock-hen);
}

C++

代码语言:javascript
复制
#include <iostream>
using namespace std;
int main()
{
	int cock,hen;
	for(cock=0;cock<=20;cock++)
	for(hen=0;hen<=33;hen++)
	if(5*cock+3*hen+(100-cock-hen)*1.0/3==100)
	cout<<"cock="<<cock<<" "<<"hen="<<hen<<" "<<"chick="<<100-cock-hen<<endl;
}

Python

代码语言:javascript
复制
for cock in range(21):
    for hen in range(34):
        if 5*cock+3*hen+(100-cock-hen)/3==100:
            print("cock=",cock,"hen=",hen,"chick=",100-cock-hen)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-02-17,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档