0% found this document useful (0 votes)
117 views2 pages

Algoritmul Lui Markov

This document contains the code for a C++ program that performs Markov chain text generation. It defines a struct called "productie" to store word pairs from a training text file. It reads word pairs into an array of productie structs, takes a seed word as input, and iteratively replaces that word with the next word in the chain according to the pairs read from the training file. It prints the resulting generated text.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views2 pages

Algoritmul Lui Markov

This document contains the code for a C++ program that performs Markov chain text generation. It defines a struct called "productie" to store word pairs from a training text file. It reads word pairs into an array of productie structs, takes a seed word as input, and iteratively replaces that word with the next word in the chain according to the pairs read from the training file. It prints the resulting generated text.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// markov.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "stdlib.h"
#include <iostream>
#include <fstream>
#include "math.h"
#include <string>
using namespace std;
struct productie{
string x,y;
};
productie prod1;
int _tmain(int argc, _TCHAR* argv[])
{
string cuvant;
productie prod[20];
int nr,poz;
//prod.x= "";
//cout<<prod.x<<endl;
//prod.y= "";
///*char numefis[100];
//char a[100];*/
//cuvant ="aaa#aa";
cout<<"cuvantul este"<<endl;
cin>>*&cuvant;
cout<<"Vector prod"<<endl;
ifstream f1("intrare.txt");
int i=1;
int found;
int n=-1;
while (!f1.eof( ))
{
f1>>prod[i].x;
f1>>prod[i].y;
cout<<i<<" "<<prod[i].x<<" -> "<<prod[i].y<<endl;
i++;
n=i;
};
cout<<"cuvantul este:"<<endl;
cout<<cuvant<<endl;
int gasit;
found = cuvant.find("l");
while (found!=-1)
{
found = cuvant.find("l");
cuvant.replace(found,1,"");
found = cuvant.find("l");
};
for (i=1;i<n;i++)
{

//cout<<prod[i].x<<" -> "<<prod[i].y<<endl;


found = cuvant.find(prod[i].x);
if (found!=-1)
{
cout<<cuvant;
cuvant.replace(found,prod[i].x.length(),prod[i].y);
cout<<".."<<i<<".."<<cuvant<<endl;
i=0;
}
found = cuvant.find("l");
while (found!=-1)
{
found = cuvant.find("l");
cuvant.replace(found,1,"");
found = cuvant.find("l");
};
found = cuvant.find(".");
if (found!=-1)
{
cout<<cuvant;
cuvant.replace(found,prod[i].x.length(),prod[i].y);
cout<<".."<<i<<".."<<cuvant<<endl;
i=n;
};
};
cout<<cuvant<<endl;
//cout<<prod1.x<<" "<<prod1.y;
/*cout<<"Nume fisier"<<endl;
ofstream fisd;
cin>>numefis;
fisd.open(numefis,ios::out);
cout<<a;
fisd.close();
cout<<"test"<<endl;*/
return 0;
}

You might also like