begin process at 2012 05 27 14:49:30
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Application

 > CONSTRUCTION D'UNE AUTOMATE FINIS DETERMINISTE

CONSTRUCTION D'UNE AUTOMATE FINIS DETERMINISTE


 Information sur la source

 Description

avec mon programme, vous pouvez construire une automate finis deterministe et meme essayer quelques mot pour savoir est ce qu'ils appartienne a son langage ou nn.

Source

  • // AFD.cpp
  • // Copyright 2010 Bilel <skible@skible-laptop>
  • //
  • // This program is free software; you can redistribute it and/or modify
  • // it under the terms of Mr Msekni Bilel.
  • //
  • // This program is distributed in the hope that it will be useful,
  • // but WITHOUT ANY WARRANTY; without even the implied warranty of
  • // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • // GNU General Public License for more details.
  • #include<stdio.h>
  • #include<stdlib.h>
  • #include<string.h>
  • struct etat
  • {
  • int init;
  • int fini;
  • etat *succ;
  • };
  • struct combo
  • {
  • char transition[2];
  • etat *tete_etat;
  • combo *succ;
  • };
  • typedef combo* COMBO;
  • typedef etat* ETAT;
  • COMBO construire()
  • {
  • //Ici on fait la construction de notre automate.
  • int replicate(ETAT tete_etat,int init,ETAT tete_combo);
  • char condition1 [4],condition2 [4];
  • combo* tete_combo=NULL;
  • combo *p_combo;
  • etat *p_etat;
  • combo* suiv=NULL;
  • etat* ref=NULL;
  • int l=0;
  • do
  • {
  • p_combo= (combo*)malloc(sizeof (combo));
  • printf("Donnez une transition\n");
  • scanf("%s",(*p_combo).transition);
  • if (tete_combo==NULL) p_combo->tete_etat=NULL;
  • else{ p_combo->tete_etat=tete_combo->tete_etat;
  • ref=tete_combo->tete_etat;
  • }
  • do
  • {
  • p_etat=(etat*)malloc(sizeof (etat));
  • do
  • {
  • printf("Donnez etat initial\n");
  • scanf("%i",&(*p_etat).init);
  • l=replicate(p_combo->tete_etat,p_etat->init,ref);
  • if (l==1) printf("ERREUR, Il existe deja une transition commencant de cette etat init\n");
  • }
  • while(l!=0);
  • printf("Donnez etat final\n");
  • scanf("%i",&(*p_etat).fini);
  • p_etat->succ=p_combo->tete_etat;
  • (*p_combo).tete_etat=p_etat;
  • printf("Voulez vous ajouter d'autres etats pour cette transition ? (oui/non)\n");
  • scanf("%s",condition1);
  • l=strcmp(condition1,"non");
  • }
  • while (l!=0);
  • (*p_combo).succ=tete_combo;
  • tete_combo=p_combo;
  • printf("Voulez vous ajouter d'autres transitions ? (oui/non)\n");
  • scanf("%s",condition2);
  • l=strcmp(condition2,"non");
  • }
  • while(l!=0);
  • p_combo=tete_combo;
  • do
  • {
  • suiv=p_combo->succ;
  • do
  • {
  • printf("%s\t",p_combo->transition);
  • printf("%i\t",p_etat->init);
  • printf("%i\t",p_etat->fini);
  • printf("\n");
  • p_etat=p_etat->succ;
  • if ((suiv==NULL)||(p_etat != suiv->tete_etat)) l=1;
  • else l=0;
  • }
  • while ((p_etat!= NULL) && l!=0);
  • p_combo=p_combo->succ;
  • } while (p_etat != NULL);
  • return (COMBO)tete_combo;
  • }
  • int replicate(etat *tete_etat,int init,etat* ref)
  • {// Ici on verifie est ce que une transition a une etat initiale identique à celui qu'on a juste tapez.
  • int replicate=0;
  • while ((tete_etat!=NULL) && (replicate==0) && (tete_etat!=ref))
  • {
  • if (tete_etat->init ==init) replicate=1;
  • else tete_etat=tete_etat->succ;
  • }
  • return replicate;
  • }
  • char* mot()
  • {
  • //Ici se fait la construction du mot qu'on va vérifier avec l'AFD.
  • int nb,i;
  • char *tab;
  • printf("Donnez la taille du mot\n");
  • scanf("%d",&nb);
  • tab= (char *) malloc((nb+1)*sizeof(char));
  • for(i=0;i<nb;i++)
  • {
  • printf("Donner la lettre %d\n",i+1);
  • scanf("%s",&tab[i]);
  • }
  • tab[nb]='\0';
  • return &tab[0];
  • }
  • char check(char* adrtab,COMBO adrcombo)
  • {
  • int res=0,trouv=1,i=0;
  • //Ici on vérifie l'appartenance du notre mot au language de notre automate.
  • int etatinit,v=0;
  • combo *ptrcombo=adrcombo;
  • etat *ptretat;
  • etat *ref=NULL;
  • printf("Donner etat de depart\n");
  • scanf("%i",&etatinit);
  • while (res==0 && trouv==1)
  • {
  • do
  • {
  • if ((*ptrcombo).transition[0]==adrtab[i]) {v=1;
  • ptretat=ptrcombo->tete_etat;
  • if (ptrcombo->succ != NULL)
  • ref=(*ptrcombo).succ->tete_etat;
  • }
  • else ptrcombo=(*ptrcombo).succ;
  • }
  • while ((v!=1)&&( ptrcombo!=NULL));
  • if (ptrcombo==NULL) trouv=5;
  • else
  • {
  • i++;
  • do
  • if ((*ptretat).init==etatinit) {v=2;
  • etatinit=(*ptretat).fini;
  • }
  • else ptretat=(*ptretat).succ;
  • while ((v!=2)&&( ptretat!=NULL)&&( ptretat!=ref));
  • if ((ptretat==NULL)||( ptretat==ref)) trouv=0;
  • else
  • if (adrtab[i]=='\0') res=1;
  • ptrcombo=adrcombo;
  • }
  • }
  • if (res==1) return etatinit;
  • else {
  • printf("Mot rejeté\n");
  • return -1;
  • }
  • }
  • int main()
  • {
  • //C'est la fonction main.
  • char rep[3];
  • int final[1],i,nb;
  • COMBO k=construire();
  • do
  • {
  • char* tab=mot();
  • printf("Votre mot est %s. On va la tester maintenant :D !!!\n",tab);
  • int s = check(tab,k);
  • if (s!=-1)
  • {
  • printf("Donnez le nombre des etats finaux\n");
  • scanf("%i",&nb);
  • for(i=0;i<nb;i++)
  • {
  • printf("Donnez etat final %i\n",i+1);
  • scanf("%i",&final[i]);
  • }
  • do
  • {
  • i--;
  • if (s==final[i]) printf("Mot Accepte\n");
  • }
  • while ((i>=0)&&(s!=final[i]));
  • if (i<0) printf("\nMot rejete");
  • }
  • printf("Voulez vous essayez un autre mot ? (oui/non)\n");
  • scanf("%s",rep);
  • }
  • while(strcmp(rep,"non")!=0);
  • return 0;
  • }
//      AFD.cpp
//      Copyright 2010 Bilel <skible@skible-laptop>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of Mr Msekni Bilel.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.

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

struct etat
			{ 
				int init;
				int fini;
				etat *succ;
			}; 
struct combo
		{
			char transition[2];
			etat *tete_etat;
			combo *succ; 
		};
		typedef combo* COMBO;
		typedef etat* ETAT;

	COMBO construire()
	{
		//Ici on fait la construction de notre automate.
	
		int replicate(ETAT tete_etat,int init,ETAT tete_combo);
		char condition1 [4],condition2 [4];
		combo* tete_combo=NULL;
		combo *p_combo;
		etat *p_etat;
		combo* suiv=NULL;
		etat* ref=NULL;
		int l=0;
	
		do
		{
			p_combo= (combo*)malloc(sizeof (combo));
		
		printf("Donnez une transition\n");
		scanf("%s",(*p_combo).transition);
		if (tete_combo==NULL) p_combo->tete_etat=NULL;
		else{ p_combo->tete_etat=tete_combo->tete_etat;
		ref=tete_combo->tete_etat;
		}
			do
			{
				p_etat=(etat*)malloc(sizeof (etat));
				
				do
				{
			printf("Donnez etat initial\n");
			scanf("%i",&(*p_etat).init);
			 
			l=replicate(p_combo->tete_etat,p_etat->init,ref);
			if (l==1) printf("ERREUR, Il existe deja une transition commencant de cette etat init\n");
				}
				while(l!=0);
			printf("Donnez etat final\n");
			scanf("%i",&(*p_etat).fini);
			p_etat->succ=p_combo->tete_etat;
				(*p_combo).tete_etat=p_etat;
			printf("Voulez vous ajouter d'autres etats pour cette transition ? (oui/non)\n");
			scanf("%s",condition1);
			l=strcmp(condition1,"non");
		    }
			while (l!=0);
			(*p_combo).succ=tete_combo;
				tete_combo=p_combo;
				
			printf("Voulez vous ajouter d'autres transitions ? (oui/non)\n");
			scanf("%s",condition2);
			l=strcmp(condition2,"non");
			
		}
			while(l!=0);
			p_combo=tete_combo;
			
		do
		{
			suiv=p_combo->succ;
			
			do
			{
				printf("%s\t",p_combo->transition);
				printf("%i\t",p_etat->init);
				printf("%i\t",p_etat->fini);
				printf("\n");
				p_etat=p_etat->succ;
				if ((suiv==NULL)||(p_etat != suiv->tete_etat)) l=1;
				else l=0;
			}
			while ((p_etat!= NULL) &&  l!=0);
		p_combo=p_combo->succ;
		
		} while (p_etat != NULL);
		return (COMBO)tete_combo;
	}
		int replicate(etat *tete_etat,int init,etat* ref)
		{// Ici on verifie est ce que une transition a une etat initiale identique à celui qu'on a juste tapez.
			int replicate=0;

			while ((tete_etat!=NULL) && (replicate==0) && (tete_etat!=ref))
			
			{
				if (tete_etat->init ==init) replicate=1;
				else tete_etat=tete_etat->succ;
			}

			return replicate;
		}
		char* mot()
		{
			//Ici se fait la construction du mot qu'on va vérifier avec l'AFD.
			int nb,i;
			char *tab;
			printf("Donnez la taille du mot\n");
			scanf("%d",&nb);
			tab= (char *) malloc((nb+1)*sizeof(char));
			
			for(i=0;i<nb;i++)
			{
				printf("Donner la lettre %d\n",i+1);
				scanf("%s",&tab[i]);
			}
			tab[nb]='\0';
			return &tab[0];
			
		}
		char check(char* adrtab,COMBO adrcombo)
		{
			int res=0,trouv=1,i=0;
			//Ici on vérifie l'appartenance du notre mot au language de notre automate.
			int etatinit,v=0;
			combo *ptrcombo=adrcombo;
			etat *ptretat;
			etat *ref=NULL;
			
			printf("Donner etat de depart\n");
			scanf("%i",&etatinit);
			
		
				while (res==0 && trouv==1)
			{    
				  do
				  {
				  if ((*ptrcombo).transition[0]==adrtab[i]) {v=1;
															ptretat=ptrcombo->tete_etat;
															if (ptrcombo->succ != NULL)
															ref=(*ptrcombo).succ->tete_etat;
															}
				else ptrcombo=(*ptrcombo).succ;
				
			}
			
				while ((v!=1)&&( ptrcombo!=NULL));
				if (ptrcombo==NULL) trouv=5;
				else
				{
					i++;	
					   do
				if ((*ptretat).init==etatinit) {v=2;
												etatinit=(*ptretat).fini;
											}
				else ptretat=(*ptretat).succ;
				while ((v!=2)&&( ptretat!=NULL)&&( ptretat!=ref));
				if ((ptretat==NULL)||( ptretat==ref)) trouv=0;
				else 	
		           if (adrtab[i]=='\0') res=1;
		           ptrcombo=adrcombo;
			   }
			   
		   }
		  
		
		  if (res==1) return etatinit;
		  else {
			  printf("Mot rejeté\n");
			  return -1;
		  }
	   }
		int main()
		{
			//C'est la fonction main.
			char rep[3];
			int final[1],i,nb;
			COMBO k=construire();
			do
			{
			char* tab=mot();
			printf("Votre mot est %s. On va la tester maintenant :D !!!\n",tab);
			int s = check(tab,k);
			if (s!=-1)
			{
				printf("Donnez le nombre des etats finaux\n");
				scanf("%i",&nb);
			for(i=0;i<nb;i++)
			{
				printf("Donnez etat final %i\n",i+1);
				scanf("%i",&final[i]);
			}
			
			do
			{
				i--;
				if (s==final[i]) printf("Mot Accepte\n");
			}
			while ((i>=0)&&(s!=final[i]));
			if (i<0) printf("\nMot rejete");
		}
		printf("Voulez vous essayez un autre mot ? (oui/non)\n");
		scanf("%s",rep);
	}
		while(strcmp(rep,"non")!=0);
			return 0;
		}



 Sources de la même categorie

Source avec Zip Source avec une capture PROGRAMME DE SUDOKU par AffreuxJojp
Source avec Zip EVALUATEUR D'EXPRESSION ARITHMÉTIQUE par matrx180vTitanium
Source avec Zip Source avec une capture QBIBLIO GESTION DES PRÊTS par conatic
Source avec Zip Source avec une capture QL-CHATROOM V 1.0 par mature
Source avec Zip Source avec une capture GEOLOCALISATION par ganjarasta

 Sources en rapport avec celle ci

JEU DU PENDU !!!! VERSION SIMPLIFIÉE ET FACILE par seyidleite
Source avec Zip EASYLIB WIN32 C++ POUR DU PROTOTYPAGE RAPIDE par gourky
Source avec Zip Source avec une capture MORPION C++ (AVEC AFFICHAGE TEXTE PAS MAL), ET UNE SORTE D'I... par GUIGUI35400
Source avec Zip CLASSE XML ULTRA LITE par bAzilew
Source avec Zip CAPTURE D'IMAGES A PARTIR D'UNE WEBCAM, ET STOCKAGE DANS UN ... par jojok31

Commentaires et avis

Commentaire de skible le 14/03/2010 19:12:03

Yahooooooooooooooo , C mon premier Code sur Code-Source .... :)

Commentaire de fretman92 le 22/03/2010 22:09:19

Ça sent le taupin en train de reviser son DS d'info sur les automates ! ;-)
Moi c'est jeudi !!

Dsl, pas de com plus profond, pas trop de temps ces temps ci

Commentaire de skible le 25/03/2010 12:55:21

plutot c kelkin qui veut gagner du bonus pour ameliorer son note de DS :D
Wow Mon 1er commentaire :)
Merci FretMan92

Commentaire de CLio908 le 27/03/2010 10:47:54

Bonjour
J'essaie de le faire tourner sur code:block mais pb
Pourriez vous donner des exemples de données valides en entrée (transitions...)
De plus je comprends pas après un while, y faut pas des op entre { et }?
        ...
        while ((v!=1)&&( ptrcombo!=NULL));
        if (ptrcombo==NULL) trouv=5;
        ...
merci

Commentaire de CLio908 le 27/03/2010 10:54:49

pour le while j'ai pigé...
pour l'utiliser pas encore!

Commentaire de skible le 28/03/2010 16:37:37

@ Clio908
salut pour la bonne utilisation de ce code il faut que
*Les transitions soit des lettres (a..z & A..Z & 1..9)
*les états initiaux et finaux sont des entiers.
*pour taper un mot , il faut tout d'abord donner le nb des lettres puis chaque lettre à part.
*Faites bien attention pour les msg que le programme te donne (exemple Voulez vous ajouter d'autres transitions ?) pour ne pas se tromper
et en plus essayer de l'exécuter sous le microsoft studio ou bien geany , je te garantie ça marche :)
@+

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Peut-on ouvrir un fichier dans le même répértoire que l'exécutable ? [ par guiroux22 ] Peut-on ouvrir un fichier dans le même répértoire que l'exécutable ? Si oui Comment ?Merci Pb d'un exécutable [ par MELISA ] Bonjour,Voici mon pb:Lorsque je veux lancer mon exe, une fenêtre d'erreur "La création d'un document vide a échoué" apparaît.Si quelqu'un connaît ce p programme facile à résoudre [ par cabarrus ] je sais je suis une larve en programmation, c'est normale je suis un débutant. pouvez vous résoudre le problème suivant:Ecrire un programme qui demand Réalisation du discotheque (facile mais...) [ par Tsinapah ] Salut a tous,Voila, j'expose mon pb, il est assez simple a comprendre:Je dois réaliser un programme qui gere une base de données sous forme de fichier Decrypter et lancer programme exécutable [ par jockos ] J'ai un programme exéctuable (fichier .exe) qui est crypté.Je veux le décrypter et le lancer dans la foulée (l'exécuter).Le problème, c'est que quand Répertoire d'installation [ par nemmezis ] Salut,Bon j'ai besoin de récupérer le répertoire d'installation d'un exécutable à l'aide de son HINSTANCE. Le problème, c'est que cette merde de fonct Répertoire d'installation [ par nemmezis ] Salut,Bon j'ai besoin de récupérer le répertoire d'installation d'un exécutable à l'aide de son HINSTANCE. Le problème, c'est que cette merde de fonct Taille exécutable [ par Stormy ] Y aurait-t-il un moyen de réduire la taille des exécutable compilés C++ histoire d'optimiser l'ensemble. merci pour les informations et ++ à tous. erreur sur Visual C++ [ par Lorelei42 ] Bonjour, J'ai créé sur Visual C++ une DLL. J'essaie de la lier avec un exécutable. Lorsque je construis l'exécutable une erreur apparaît : LIBCD.lib(w


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,671 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales