avatar
你家猫喝茶吗?# pets - 心有所宠
f*a
1
倒水问题 5升3升的桶,倒出4升的水。要求写出code, 打印出步骤。 输入输出自己定
义。 推还是挺容易,但是转成code不知道从何下手。
★ 发自iPhone App: ChineseWeb 8.1
avatar
m*u
2
我家猫老偷喝我的普洱!
avatar
d*u
3
DP

【在 f********a 的大作中提到】
: 倒水问题 5升3升的桶,倒出4升的水。要求写出code, 打印出步骤。 输入输出自己定
: 义。 推还是挺容易,但是转成code不知道从何下手。
: ★ 发自iPhone App: ChineseWeb 8.1

avatar
H*o
4
我家的吃青菜,和绿茶。。。。好一个健康生活
avatar
n*n
6
偷喝加奶速溶咖啡,还滚烫的,不知道在想什么。
avatar
f*a
7
倒水问题 5升3升的桶,倒出4升的水。要求写出code, 打印出步骤。 输入输出自己定
义。 推还是挺容易,但是转成code不知道从何下手。
★ 发自iPhone App: ChineseWeb 8.1
avatar
h*e
8
咖啡对猫有毒,小心呐
好像茶也对猫不好的

【在 n****n 的大作中提到】
: 偷喝加奶速溶咖啡,还滚烫的,不知道在想什么。
avatar
d*u
9
DP

【在 f********a 的大作中提到】
: 倒水问题 5升3升的桶,倒出4升的水。要求写出code, 打印出步骤。 输入输出自己定
: 义。 推还是挺容易,但是转成code不知道从何下手。
: ★ 发自iPhone App: ChineseWeb 8.1

avatar
c*p
11
mark
avatar
x*e
12
Using 2 stacks to mimic the 2 bucket, suppose s1 has 5L and s2 has 3L.
Algorithm:
1) Fill s1 to be full
2) Move the water in s1 to s2 until s2 is full
3) Empty s2
4) Move the water in s1 to s2 until s1 is empty
5) Fill s1 to be full
6) Move the water in s1 to s2 until s2 is full
Code:
#include
using namespace std;
const int kSize1 = 5;
const int kSize2 = 3;
void PourWater(stack &s1, stack &s2) {
for (int i = 0; i < kSize1; i++) {
s1.push(1);
}
for (int i = 0; i < kSize2; i++) {
int temp = s1.top();
s1.pop();
s2.push(temp);
}
while (!s2.empty()) {
s2.pop();
}
while (!s1.empty()) {
int temp = s1.top();
s1.pop();
s2.push(temp);
}
for (int i = 0; i < kSize1; i++) {
s1.push(1);
}
while (s2.size() != kSize2) {
int temp = s1.top();
s1.pop();
s2.push(temp);
}
}

【在 f********a 的大作中提到】
: 倒水问题 5升3升的桶,倒出4升的水。要求写出code, 打印出步骤。 输入输出自己定
: 义。 推还是挺容易,但是转成code不知道从何下手。
: ★ 发自iPhone App: ChineseWeb 8.1

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。