Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. int minMove_CEH(int* students, int len)
  2. {
  3. int zeroCount[2] = { 0, };
  4. int minMove[2] = { 0, };
  5. for (int i = 0; i < len; i++)
  6. {
  7. if (students[i] == 0)
  8. zeroCount[0]++;
  9. else
  10. minMove[0] += zeroCount[0];
  11.  
  12. if (students[len - i - 1] == 0)
  13. zeroCount[1]++;
  14. else
  15. minMove[1] += zeroCount[1];
  16. }
  17.  
  18. return minMove[0] < minMove[1] ? minMove[0] : minMove[1];
  19. }
  20.  
  21. TEST(Algorithm2, Quiz) {
  22. EXPECT_EQ(minMove(new int[8]{ 1, 1, 1, 1, 0, 0, 0, 0 }, 8), 0);
  23. EXPECT_EQ(minMove(new int[8]{ 1, 0, 1, 1, 0, 0, 0, 0 }, 8), 2);
  24. EXPECT_EQ(minMove(new int[8]{ 0, 1, 0, 1, 1, 0, 1, 1 }, 8), 4);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement