daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top