C++逃跑的蠕虫

void 逃跑的蠕虫()
{//缘由https://bbs.csdn.net/topics/394844062
	int 爬行 = 0, 滑行 = 0, 距离 = 0, 分钟 = 0;
	string 结果 = "";
	while (scanf_s("%d %d %d", &滑行, &爬行, &距离))
	{
		if (爬行 == 滑行 && 滑行 == 距离 && 距离 == 0) break;
		if (滑行 < 爬行 && 滑行 < 距离)
		while (距离)
		if (距离 > 爬行)
		{
			分钟 += 2;
			距离 -= 爬行 - 滑行;
		}
		else if (距离 <= 爬行)
		{
			分钟 += 1;
			结果 += to_string(分钟) + "分钟^_^\n";
			距离 = 分钟 = 0;
		}
		else continue;
	}
	cout << 结果;
}
void 逃跑的蠕虫()
{//缘由https://bbs.csdn.net/topics/394844062
	int 爬行 = 0, 滑行 = 0, 距离 = 0, 分钟 = 0;
	string 结果 = "";
	while (scanf_s("%d %d %d", &滑行, &爬行, &距离))
	{
		if (爬行 == 滑行 && 滑行 == 距离 && 距离 == 0) break;
		if (滑行 < 爬行 && 滑行 < 距离)
		while (距离)
		if (距离 > 爬行)
			分钟 += 2,
			距离 -= 爬行 - 滑行;
		else //if (距离 <= 爬行)
			++分钟,
			结果 += to_string(分钟) + "分钟^_^\n",
			距离 = 分钟 = 0;
		else continue;
	}
	cout << 结果;
}
string 逃跑爬行(int 爬行, int 滑行, int 距离)
{
	int 分钟 = 0;
	string 结果 = "";
	while (距离)
	if (距离 > 爬行)
		分钟 += 2,
		距离 -= 爬行 - 滑行;
	else //if (距离 <= 爬行)
		分钟 += 1,
		结果 = to_string(分钟) + "分钟^_^\t",
		距离 = 分钟 = 0;
	return 结果;
}
void 逃跑的蠕虫()
{//缘由https://bbs.csdn.net/topics/394844062
	int 爬行 = 0, 滑行 = 0, 距离 = 0;
	string 结果 = "";
	while (scanf_s("%d %d %d", &滑行, &爬行, &距离))
	{
		if (爬行 == 滑行 && 滑行 == 距离 && 距离 == 0) break;
		if (滑行 < 爬行 && 滑行 < 距离) 结果 += 逃跑爬行(爬行, 滑行, 距离) + "\n";
		else continue;
	}
	std::cout << 结果;
}
int _tmain(int argc, _TCHAR* argv[])
{
起始:
	clock_t start = clock();
	int 滑行 = 18, 爬行 = 19, 距离 = 20, 量 = 0;
	while (距离)
	{
		std::cout << 滑行 << " " << 爬行 << " " << 距离 << " " << 蠕虫的爬行(滑行, 爬行, 距离);
		if (++量 % 5 == 0)cout << endl;
		if (--滑行 <= 0)滑行 = --爬行 - 1, cout << endl;
		if (爬行 <= 1) 爬行 = --距离 - 1;
	}
	clock_t stop = clock();
	printf_s("耗时:%lf\n", (double)(stop - start) / CLOCKS_PER_SEC);
	system("pause");
	//system("cls");
	goto 起始;
	//return 0;
}
int 逃跑的蠕虫(int 滑行,int 爬行,int 距离)
{
	int 分钟 = 1;
	while (距离 > 爬行)距离 -= 爬行, 距离 += 滑行, 分钟 += 2;
	return 分钟;
}
int 逃跑的蠕虫(int 滑行,int 爬行,int 距离)
{
	int 分钟 = 1;
	while (距离 > 爬行)距离 -= 爬行 - 滑行, 分钟 += 2;
	return 分钟;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值