1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| struct coupleValeur
{
int a;
int b;
struct coupleValeur* next;
struct coupleValeur* prev;
};
void supprimeDoublon(struct coupleValeur* first)
{
struct coupleValeur *liste = first;
while (liste)
{
struct coupleValeur* it = liste->next;
while (it)
{
if (it->a == liste->b && it->b == liste->a && it->a != it->b)
{
if (it->prev)
{
it->prev->next = it->next;
it->next->prev = it->prev;
}
}
it = it->next;
}
liste = liste->next;
}
}
void afficherListe(struct coupleValeur* liste)
{
while (liste)
{
std::cout << liste->a << "/" << liste->b << std::endl;
liste = liste->next;
}
}
int countEgal(struct coupleValeur* liste)
{
int ret = 0;
while (liste)
{
if (liste->a == liste->b)
ret++;
liste = liste->next;
}
return ret;
}
int count(struct coupleValeur* liste)
{
int ret = 0;
while (liste)
{
ret++;
liste = liste->next;
}
return ret;
}
int main(int argc, char* argv[])
{
int valMax = 1;
int* valeur;
valeur = new int[valMax];
int i = 0;
while (i < valMax)
{
valeur[i]=++i;
}
struct coupleValeur *listeValeur = 0;
struct coupleValeur* current = 0;
int ia = 0;
int ib = 0;
while (ia < valMax)
{
ib = 0;
while (ib < valMax)
{
struct coupleValeur *elem = new coupleValeur;
elem->next = 0;
elem->prev = current;
elem->a = valeur[ia];
elem->b = valeur[ib];
if (current == 0)
{
listeValeur = elem;
current = elem;
}
else
{
current->next = elem;
current = current->next;
}
ib++;
}
ia++;
}
supprimeDoublon(listeValeur);
//afficherListe(listeValeur);
int nbEgal = countEgal(listeValeur);
int nb = count(listeValeur);
std::cout << "probabilite que a == b est de " << (nbEgal*100)/nb << "%" << std::endl;
system("PAUSE");
return 0;
} |