标题:求助:10L的瓶子装满水,再给你一个3L,一个7L的瓶子,分出2个5L的水!
只看楼主
yxb0001
Rank: 2
等 级:论坛游民
帖 子:50
专家分:35
注 册:2009-9-9
得分:0 
#include<iostream>
using namespace std;
 
void main()
{
    int sa,sb,sc; //sa,sb,sc分别表a,b,c瓶子实际盛水量
    int la=10,lb=3,lc=7,sum=10; //la,lb,lc表各瓶子的容量,sum表水的总量。
    sa=sum;
    sb=0;
    sc=0;
    while(sc<lc)
    {
        sc++;
 
    }
    cout<<"sa="<<(sa-sc)<<",sb="<<sb<<",sc="<<sc<<"\n";
    sa=sa-sc;
    do{sb++;}while(sb<lb);
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<(sc-sb)<<"\n";
    sc=sc-sb;
    if(sb==lb)
    {
        sa=sa+sb;
        sb=sb-lb;
    }
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<sc<<"\n";
    while(sb<lb){sb++;};
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<(sc-sb)<<"\n";
    sc=sc-sb;
    if(sb==lb)
    {
        sa=sa+sb;
        sb=sb-lb;
    }
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<sc<<"\n";
    if(sb==0)
    {
        sb=sb+sc;
        sc=sc-sc;
    }
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<sc<<"\n";
    while(sc<lc)
    {sc++;}
    sa=sa-sc;
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<sc<<"\n";
    while(sb!=lb)
    {
        sb++;
        sc--;
    }
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<sc<<"\n";
    while(sb!=0)
    {
        sb--;
        sa++;
    }
    cout<<"sa="<<sa<<",sb="<<sb<<",sc="<<sc<<"\n";
 
}
2009-09-14 15:34
DreamerLJX
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-10-26
得分:0 
刚才楼上有人说定义四个变量,三个代表瓶子,一个作为临时存水的瓶子,那么这个临时存水瓶子的容积该怎么计算呢?
2015-10-26 19:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-285091-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.125577 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved