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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define NM 30
/* ======================================= */
char dict[NM][18]={"dimanche","presenter","attitude","projet","codeblocks","message","communication","chiffres","lettres","electronique","programmation","bonjour","salut","informatique"};
/* ======================================= */
void saisielettre(int NL ,char *p)
{
int j;
for (j=0;j<NL;j++)
{
printf("Donner le caractere n %d \n",j);
*(p+j)=getch();
}
}
/* ======================================= */
void Redlettres(int NL,char Tlettres[NL],int *p)
{
int i,j;
char Tred[NL];
for (i=0;i<NL;i++)
{
*(p+i)=-1;
}
for (i=0;i<NL;i++)
{
if (Tlettres[i]==(-1))
{*(p+i)=1;
for (j=i+1;j<NL;j++)
{
if (Tlettres[j]==Tlettres[i])
{(*(p+i))++; *(p+j)=0; }
}
}
}
}
/* ======================================= */
int LettreExiste(char lettre, char mot[18])
{ int i=0,L=strlen(mot);
int existe=0;
do
{
if (lettre==mot[i]) {existe=1;} else {i++;}
} while ((existe==0)&&(i<L));
return existe;
}
/* ======================================= */
int MExclut(int NL ,char Tlettres[NL],char dict[NM][12], int i)
{
int L=strlen(dict[i]);
int j=0,exclu=0;
do
{ if (LettreExiste(dict[i][j], Tlettres)) {j++;} else {exclu=1;}
} while ((j<L)&&(exclu==0));
return exclu;
}
/* ======================================= */
int menu()
{
int n;
printf("***************** 1.jouer aux lettres ********************\n");
printf("***************** 2.jouer aux chiffres *****************\n");
printf("***************** 3.remerciement **********************\n");
scanf("%d",&n);
return n;
}
/* ======================================= */
/* ********La fonction score************ */
int score(int NL ,char Tlettres[NL],char dict[NM][12], int i)
{
int j,k,exces=0, scoretot=0;
int Tscore[NL], L=strlen(dict[i]);
for (i=0;i<NL;i++) {Tscore[i]=0;}
int Tred[NL];
Redlettres(NL,Tlettres,Tred);
if (MExclut(NL ,Tlettres,dict,i)) {return -1;}
else
{
for (j=0;j<L;j++)
{
for (k=0;k<NL;k++)
{
if ((dict[i][j]==Tlettres[k])&&(Tred[k]>0)) {Tscore[k]++; }
}
}
}
for (k=0;k<NL;k++) { scoretot+=Tscore[k]; if (Tscore[k]>Tred[k]) {exces=1;} }
if (exces) { return -1; } else { return scoretot;}
}
/* ======================================= */
int MotRetenu(int NL, char Tlettres[NL], char dict[NM][12])
{
int i, imax=0, scoremax=score(NL,Tlettres,dict, 0);
for (i=1;i<NM;i++)
{ if (scoremax<score(NL,Tlettres,dict, i)) {imax=i; scoremax=score(NL,Tlettres,dict, i);} }
return imax;
}
/* ============================================ */
int main(int argc, char *argv[])
{
int choix;
char Tlettres[9];
char dict[30][12];
int NL=9;int x;
choix=menu();
switch (choix)
{
case 1: saisielettre(NL,Tlettres);
printf("%s \n",Tlettres);
char y;
x=MotRetenu(NL,Tlettres,dict);
printf("le mot retenue est : %d \n ",x);
getchar();
choix=menu();
case 2: printf("nous sommes desole de ne vous faire pas la partie de chiffres on vous presente un autre jeux appelant 'plus ou moins'");
int nombreMystere = 0, nombreEntre = 0;
const int MAX = 100, MIN = 1;
srand(time(NULL));
nombreMystere = (rand() % (MAX - MIN + 1)) + MIN;
do
{
printf("Quel est le nombre ? ");
scanf("%d", &nombreEntre);
if (nombreMystere > nombreEntre)
printf("C'est plus !\n\n");
else if (nombreMystere < nombreEntre)
printf("C'est moins !\n\n");
else
printf ("Bravo, vous avez trouve le nombre mystere !!!\n\n");
} while (nombreEntre != nombreMystere);
choix=menu();
case 3: printf("remerciment");
default : break; }
return 0;
} |
Partager