东华大学 2022 oj c++ 无超纲写法 学做菜

 //不太懂题目想干嘛,我也不知道我在干嘛...

//我知道还有好多地方可以优化,偷懒了

//个人认为比两年前那位学姐发的更简洁(勿喷,欢迎讨论)

AC代码:

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<iomanip>
//1、 西红柿炒鸡蛋 原料:AABDD
//2、 酸辣鸡丁 原料:ABCD
//3、 宫保鸡丁 原料:CCD
//4、 水煮西红柿 原料:BBB
//5、 怪味蛋 原料:AD
using namespace std;
int count1(int a, int b, int c, int d)
{
	int cnt = 0;
	while (a >= 2 && b >= 1 && d >= 2)
	{
		cnt++;
		a -= 2;
		b--;
		d -= 2;
	}
	return cnt;
	
};
int count2(int a, int b, int c, int d)
{
	int cnt = 0;
	while (a >= 1 && b >= 1 && d >= 1&&c>=1)
	{
		cnt++;
		a--; b--; c--; d--;
	}
	return cnt;

};
int count3(int a, int b, int c, int d)
{
	int cnt = 0;
	while ( d >= 1 && c >= 2)
	{
		cnt++;
		d--;
		c -= 2;
	}
	return cnt;

};
int count4(int a, int b, int c, int d)
{
	int cnt = 0;
	while (b>=3)
	{
		cnt++;
		b -= 3;
	}
	return cnt;

};
int count5(int a, int b, int c, int d)
{
	int cnt = 0;
	while (a >= 1 && d >= 1)
	{
		cnt++;
		a--; d--;
	}
	return cnt;

};
int main()
{
	//下测试第一个函数是否正确
	//cout << count1(5, 4, 20,8);
	//下测试第五个函数
	//cout << count5(2, 2, 5, 8);
	int a = 0, b = 0, c = 0, d = 0;
	cin >> a >> b >> c >> d;
	int x = count1(a, b, c, d);
	cout <<x << endl;
	a = a - 2 *x;
	b = b - x; 
	d = d - 2 * x;
	int y = count2(a, b, c, d);
	cout << y << endl;
	a -= y;
	b -= y;
	c -= y;
	d -= y;
	int z = count3(a, b, c, d);
	cout <<z << endl;
	c = c - 2 * z;
	d -=z;
	int p = count4(a, b, c, d);
	cout <<p << endl;
	b -= 3 * p;
	cout << count5(a, b, c, d) << endl;
	//system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值