This is the problem:
Management of the Flow
Paula is responsavel for the flow of a dam. From midnight and during the
next 24 hours, the dam will receive 'water' at a rate of 5000m3/hour. As the dam
has 2 floodgates with a flow capacity for each one of 3000m3/hour, Paula asked
th dam programmer for the following behavior:
• open a floodgate in the beginning;
• monitor the volume of 'water in the dam each hour;
• when the dam is >= 100000m3, open the second floodgate, when the
volume <= 90000m3, Close the second gate.
Currently the stored water is 91000m3 of water and operations starts at 00h00m01s
Problem
The next day, to see if everything is going as planned, for each hour Paula
wonders how many gates should be open.
Input data
A line with an integer from 0 to 23 that represents an hour.
Output data
A line with the phrase "a gate" or "two gates" as the number of
gates that should be open at that time.
Example of input data
18
Example output data
a gate
This is how i solved it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
int main(void){
bool duas=false;
int bv=91000;
int h,a;
do{
cin>>h;
}
while((h>23)||(h<0));
for (a=0;a<h;a++)
{
if (duas==true){
bv = bv + 5000;
bv = bv - 6000;
if (bv<=90000){
duas=false;}
}
else{
bv=bv+5000;
bv=bv-3000;
if (bv>=100000){
duas=true;}
}
}
if (duas==true){
cout<<"two gates"<<endl;
}
else
{
cout<<"one gate"<<endl;
}
system("pause");
}
|
The thing is, i can't stop wondering about other solutions.
Can you guy's show a better way for this?