Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Emlm-EngMlm.cpp : Defines the entry point for the console application.
- //Eng-MlM by Konstantinos Peratinos
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <sstream>
- using namespace std;
- double Qj ( int k,double j,vector<double>& a,vector<double>& b){
- double i=0;
- double jqj=0;
- if (j==0)
- {
- return 1.0;
- }
- else if(j<0)
- {return 0.0;
- }
- else
- {
- for (i=0;i<k;i++)
- {
- jqj=jqj+(a[i]*b[i]*Qj(k,j-b[i],a,b));
- }
- return jqj/j;
- }}
- double Yj (int cat,double g,vector<double>& a,vector<double>& b,vector<double>& q)
- {double ykj=0;
- if (g-b[cat]<0)
- {cout<<"0\n";
- return 0;}
- else{
- ykj=(a[cat]*q[g-b[cat]])/q[g];
- cout<<ykj<<"\n";
- return ykj;}
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- string line;
- int k=0,c=0;
- int cat=0,i=0;
- int g=0;
- double sum=0,j=0,jj=0;
- vector<double> a,b,q,r;
- vector < vector <double> > yj;
- //Reading The Input Values from the file
- fstream input_File("input.txt");
- if (input_File.is_open())
- {
- while(getline(input_File,line))
- {
- if (line[0] != '/')
- {
- double dob;
- istringstream iss(line);
- while(iss>>dob)
- {
- i++;
- if (i==1)
- {k=dob;}
- else if(i==2)
- {c=dob;}
- else
- {i%2==1? a.push_back (dob):b.push_back (dob);} // Oi Arties Times apoteloun ta a, oi perites ta b
- }
- }
- }// Ypologizontas ta Q(j)
- for (j=0;j<=c;j++)
- {
- q.push_back(Qj(k,j,a,b));
- sum=sum+Qj(k,j,a,b);
- }
- for (i=0;i<q.size();i++)
- {
- q[i]=(q[i]/sum);
- cout<<q[i]<<"\t";
- }
- cout<<endl<<"k is "<<k<<"\t"<<"and C is "<<c<<endl;
- for (cat=0;cat<k;cat++)
- {r.clear();
- for (jj=0;jj<=c;jj++)
- {r.push_back(Yj(cat,jj,a,b,q));}
- yj.push_back(r);}
- for (int q=0;q<k;q++){
- for (int qq=0;qq<=c;qq++)
- {cout<<yj[q][qq]<<"\t";}}
- input_File.close();
- cin >> line;
- return 0 ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement