| |

VerySource

 Forgot password?
 Register
Search
View: 974|Reply: 7

Encounter a problem, seek a solution

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-15 21:30:01
| Show all posts |Read mode
Encountered a problem, seeking a solution:
There are 4 pumps in a pumping station. When the pumps are turned on:
Step 1: Check the normal signs of the 4 pumps first, and start only the normal pumps.
Step 2: When the number of normal pumps is greater than or equal to 2, start the 2 pumps with the smallest number of starts.
Step 3: After starting the pump, add 1 to the number of pump starting. Then loop.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-17 23:15:01
| Show all posts
How to write in a loop?
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-19 15:00:01
| Show all posts
for (int i=0; i<=3; i++)
{
    if (Pump[i].IsNormal())
   {
        NumOfNormal++;
        NormalPumpArray.Add(Pump[i]); // pass the reference
    }
}

SortByStartTimes (NormalPumpArray);

if (NumOfNormal>=2)
{
       for (int j=0; j<2; j++)
       {
            NormalPumpArray[i].StartUp();
            NormalPumpArray[i].AddCount(); // it's better to add count in StartUp function
       }
}
else
{
      for (int j=0; j<NumOfNormal; j++)
     {
            NormalPumpArray[j].SartUP();
            NormalPumpArray[j].AddCount();
     }
}
Reply

Use magic Report

1

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-12-19 21:00:01
| Show all posts
struct ben
{
int normalflag;//normal flag
int startflag;//Start flag
int startcount;//start count

};
ben arr[4];
int min=999999; int k=-1;int t=0;
int normalcount()
{
int temp;
for (int i=0;i<4;i++)
if(normal[i].normalflag)
temp++;
return temp;
}
int normalnum=normalcount();
if(normalnum>=2)
{
for (int i=0;i<4;i++)
{
if(arr[i].normalflag&&arr[i].startcount<min&&i!=k)
  {
   min=arr[i].startcount;
   temp[t]=i;//The subscripts of the smallest two normal pumps
    k=i;
  }
  if(i==4)
  {
   i=0;
   t++;
  }
  if(t==2) break;
}
for(i=0;i<4;i++)

  for(j=0;i<t;j++)
{
if(i==temp[j])
arr[i].startflag=1;
else arr[i].startflag=0;
}
Reply

Use magic Report

1

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-12-19 22:45:01
| Show all posts
Probably write it, think carefully for yourself
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-12-20 02:00:01
| Show all posts
Then what does it mean to loop?
Continue to start the others? Then it might as well start all at once.
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-20 07:00:01
| Show all posts
Maybe the host wants to implement something similar to a worker thread, which is to keep the pump in working condition.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-20 16:15:01
| Show all posts
I can't understand how I look at it!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list