Documente Academic
Documente Profesional
Documente Cultură
Cadenas aceptadas:
11
00000110000
11000
0000011
01111000
Cadenas no aceptadas:
001100110
0000111
111000
0101011
110011
/*
* Automata11
* Copyright (C) 2017 Roberto Lopez
marcos.robrto.lopez@gmail.com
*
* This program is free software; you
can redistribute it and/or
* modify it under the terms of the GNU
General Public License
* as published by the Free Software
Foundation; either version 2
* of the License, or (at your option)
any later version.
*
* 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.
*
* You should have received a copy of
the GNU General Public License
* along with this program; if not,
write to the Free Software
* Foundation, Inc., 59 Temple Place -
Suite 330, Boston, MA 02111-1307, USA.
*/
package com.rlopez.demo.automata;
import javax.swing.JOptionPane;
/**
*
*/
public class Automata11 {
//init state
public Automata11() {
state = Q0;
}
}
}
}
}
Programacion de
automatas!
Quisiera que me ayudaran, hace unos días
me dejaron un ejercicio en java, lo pude
hacer por utilizando "matches" y el profesor
me dijo que no lo quería así, utilizando
solamente cadeas (strings) el ejerció a
resolver es este:
(a|b?|c)+a
Quisiera que me ayudaran con un ejemplo
de como programarlo de antemano.
SEGUIR
1 RESPUESTA
RESPUESTA DE FBLUISG
package automata;
/**
*
*@authorDancourbano*/
import java.util.Scanner;
String cadena;
//String cadena ="ababa";
Scanner teclado=new Scanner(System.in);
Automata aut = new Automata();// TODO code application logic here
cadena=teclado.next();
aut.car = cadena.toCharArray();
aut.inicio();
if(aut.aceptado)
System.out.println("aceptacion");
else System.out.println("no aceptacion");
}
public void inicio(){
cont =0;
q0();
}
public void q0(){
System.out.println("En q0");
aceptado=false;
if(cont<car.length){
if(car[cont]=='a'){
cont++;
q1();
}else if(car[cont]=='b'){
cont++;
q4();
}
}//else System.out.println("En error");
}
public void q1(){
System.out.println("En q1");
if(cont<car.length){
if(car[cont]=='b'){
cont++;
q2();
}}
}
public void q3(){
System.out.println("En q3 ");
aceptado=true;
if(cont<car.length){
if(car[cont]=='a'){
cont++;
q3();
}else if(car[cont]=='b'){
cont++;
qerror();
}
}//else System.out.println("En aceptacion");
}
public void q4(){
System.out.println("En q4");
if(cont<car.length){
if(car[cont]=='a'){
cont++;
q4();
}else if(car[cont]=='b'){
cont++;
q5();
}
}//else System.out.println("En error");
}
public void q5(){
System.out.println("En q5 ");
aceptado=true;
if(cont<car.length){
if(car[cont]=='a'){
cont++;
q5();
}else if(car[cont]=='b'){
cont++;
qerror();
}
}//else System.out.println("En aceptacion");
}
Autómata Finito Determinista
Que Reconoce el Lenguaje
[a.a*aa*]
Unknown jueves, julio 14, 2011
CODIFICACIÓN EN C++
//AUTOMATAS DETERMINISTAS =
DEFINIDO
#include<iostream>
using namespace std;
return 0;
}
while(palabra[i])
{
estado = mover(estado,palabra[i]);
i++;
}
return 0;
}
int main()
{
system("color f0");
while(1)
{
char palabra[10];
if( scanner(palabra))
cout<<"\n\n\t\t\t Corecto !!! ";
else
cout<<" \n\n\t\t\t Error !!!!";
cout<<endl<<endl;
system("pause");
system("cls");
}
return 0;