Documents

gramatica

Description
Description:
Categories
Published
of 2
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Share
Transcript
  import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.*;public class Gramatica {public static void main(String[] args) throws FileNotFoundException {FileInputStream fisier = new FileInputStream( D:\\Java\\Laborator LF\\GramaticaGenerativa\\intrari );Scanner citire_fisier = new Scanner(fisier);Scanner scanner= new Scanner(System.in);ArrayList<String> stanga = new ArrayList<String>();ArrayList<String> dreapta = new ArrayList<String>();String cuvant=new String();int nr_reguli = Integer.parseInt(citire_fisier.next());String S=citire_fisier.next();for (int i=0; i<nr_reguli; i++) {stanga.add(citire_fisier.next());dreapta.add(citire_fisier.next());System.out.println( Regula nr. + (i+1) + : + stanga.get(i) + + dreapta.get(i));}citire_fisier.close();System.out.println( Nr.de cuvinte de generat: );int nr_cuv=scanner.nextInt();for(int i=0;i<nr_cuv;i++) {cuvant=cuvant.concat(S); Vector<Integer> regula_folosita=new Vector<Integer>(); int nr_reg_fol,pozitie=0;System.out.println( Rezultat intermediar este: +cuvant);do{regula_folosita.clear();nr_reg_fol=0;for(int j=1;j<nr_reguli;j++){pozitie=cuvant.indexOf(stanga.get(j));if(pozitie!=-1)  {regula_folosita.add(nr_reg_fol,j);nr_reg_fol++;}}if ((nr_reg_fol!=0)) {Random rand=new Random();int reg=rand.nextInt(nr_reg_fol); cuvant=cuvant.replaceFirst(stanga.get(regula_folosita.get(reg)), dreapta.get(regula_folosita.get(reg)));System.out.println( rezultat intermediar : +cuvant);}}while ((nr_reg_fol!=0) || (pozitie!=-1));System.out.println( Rezultatul final este: + cuvant);}scanner.close();}}
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x