// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

void init(int *team, int n)
{
   for(int i = 0; i < n; i++)
   {
      team[i] = 0;
   }
}

int count(int *team, int n, int v)
{
   int res = 0;
   for(int i = 0; i < n; i++)
   {
      if(team[i]==v) res++;
   }
   return res;
}

void pick(int *team, int n)
{
   while(count(team,n,1)<(n/2))
   {
      int ix = (rand() >> 8) % n;
      team[ix] = 1;
   }
}

void fill(int *team, int n)
{
   for(int i = 0; i < n; i++)
   {
      if(team[i]==0) team[i] = 2;
   }
}

void show(int *team, string *names, int n, int v)
{
   cout << "Team " << v << ":" << endl;
   for(int i = 0; i < n; i++)
   {
      if(team[i]==v) cout << names[i] << endl;
   }
}

int main()
{
   cout << "Enter number of players: ";
   int n;
   cin >> n;
   string *names = new string[n];
   for(int i = 0; i < n; i++)
   {
      cout << "Enter player " << (i+1) << ":";
      cin >> names[i];
   }
   int *team = new int[n];
   init(team,n);
   srand(time(NULL));
   pick(team,n);
   fill(team,n);
   show(team,names,n,1);
   show(team,names,n,2);
   return 0;
}

