#include <stdio.h> 
#include <stdlib.h>

#define TRUE 1
#define FALSE 0
#define bool int

#define TAILLE 256

typedef struct multiset {int t[TAILLE];} multiset;


multiset me_vide()
{
  int i;
  multiset m;
  for (i=0;i<TAILLE;i++) m.t[i]=0;
  return m;
}

void print(multiset m)
{
  int i,j;
  for (i=0;i<TAILLE; i++)
    for (j=0; j<m.t[i]; j++)
      printf("%c ",i);
  printf("\n");
}


void add(char c, multiset *m)
{
  (m->t[c])++;
}

void me_remove(char c, multiset *m)
{
  if (m->t[c]>0) m->t[c]--;
}

int nb_occ(char c, multiset m)
{
  return (m.t[c]);
}

bool appartient(char c, multiset m)
{
  return (m.t[c]>0);
}

bool inclus(multiset a, multiset b)
{
  bool res=TRUE;
  int i;
  for(i=0;i<TAILLE&&res;i++)
      res=(a.t[i]<=b.t[i]);
  return res;
}

bool egal(multiset a, multiset b)
{
  return (inclus(a,b) && inclus(b,a));
}

int min(int a, int b)
{
  if (a<=b) return a; else return b;
}

int max(int a, int b)
{
  if (a>=b) return a; else return b;
}


multiset intersection(multiset a, multiset b)
{
  multiset r;
  int i;
  for(i=0;i<TAILLE;i++)
    r.t[i]=min(a.t[i],b.t[i]);
  return r;
}

multiset reunion(multiset a, multiset b)
{
  multiset m;
  int i;
  for(i=0;i<TAILLE;i++)
    m.t[i]=max(a.t[i],b.t[i]);
  return m;
}

int cardinal_diff(multiset a)
{
  int c=0;
  int i;
  for(i=0;i<TAILLE;i++)
    if (a.t[i]!=0) c++;
  return c;
}

int cardinal_total(multiset a)
{
  int i,c=0;
  for(i=0;i<TAILLE;i++)
    c+=a.t[i];
  return c;
}

int main()
{
  printf("quelques tests...\n");
  multiset f=me_vide();
  add('c',&f);
  add('d',&f);
  add('e',&f);
  add('d',&f);
  printf("f = "); print(f);


  add('e', &f);
  printf("f = "); print(f);
  me_remove('d',&f);
  printf("f = "); print(f);
  printf("#h = %d\n",nb_occ('h', f));
  printf("#c = %d\n",nb_occ('c',f));
  printf("#e = %d\n",nb_occ('e',f));

  multiset a=me_vide();
  add('c', &a);
  add('h', &a);
  add('i', &a);
  add('e', &a);
  add('n',&a);
  printf("a = "); print(a);

  multiset b=me_vide();
  add('n',&b);
  add('i',&b);
  add('c',&b);
  add('h',&b);
  add('e',&b);
  printf("b = "); print(b);

  if (appartient('c',a)) printf("appartient\n");
  else printf("n'appartient pas\n");

  if (appartient('w',a)) printf("appartient\n");
  else printf("n'appartient pas\n");
  
  if (inclus(a,b)) printf("inclus\n"); else printf("non inclus\n");
  if (inclus(f,b)) printf("inclus\n"); else printf("non inclus\n");
  if (inclus(a,f)) printf("inclus\n"); else printf("non inclus\n");

  if (egal(a,b)) printf("egal\n"); else printf("different\n");
  if (egal(f,b)) printf("egal\n"); else printf("different\n");
  if (egal(a,f)) printf("egal\n"); else printf("different\n");
}
