Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. // Emlm-EngMlm.cpp : Defines the entry point for the console application.
  2. //Eng-MlM by Konstantinos Peratinos
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <vector>
  9. #include <sstream>
  10.  
  11. using namespace std;
  12.  
  13. double Qj ( int k,double j,vector<double>& a,vector<double>& b){
  14. double i=0;
  15. double jqj=0;
  16. if (j==0)
  17. {
  18. return 1.0;
  19. }
  20. else if(j<0)
  21. {return 0.0;
  22. }
  23.  
  24. else
  25. {
  26. for (i=0;i<k;i++)
  27. {
  28. jqj=jqj+(a[i]*b[i]*Qj(k,j-b[i],a,b));
  29. }
  30. return jqj/j;
  31. }}
  32.  
  33. double Yj (int cat,double g,vector<double>& a,vector<double>& b,vector<double>& q)
  34. {double ykj=0;
  35. if (g-b[cat]<0)
  36. {cout<<"0\n";
  37. return 0;}
  38. else{
  39. ykj=(a[cat]*q[g-b[cat]])/q[g];
  40. cout<<ykj<<"\n";
  41. return ykj;}
  42.  
  43. }
  44.  
  45.  
  46. int _tmain(int argc, _TCHAR* argv[])
  47. {
  48. string line;
  49. int k=0,c=0;
  50. int cat=0,i=0;
  51. int g=0;
  52. double sum=0,j=0,jj=0;
  53. vector<double> a,b,q,r;
  54. vector < vector <double> > yj;
  55.  
  56.  
  57. //Reading The Input Values from the file
  58.  
  59. fstream input_File("input.txt");
  60. if (input_File.is_open())
  61. {
  62. while(getline(input_File,line))
  63. {
  64. if (line[0] != '/')
  65. {
  66. double dob;
  67. istringstream iss(line);
  68. while(iss>>dob)
  69. {
  70. i++;
  71.  
  72. if (i==1)
  73. {k=dob;}
  74. else if(i==2)
  75. {c=dob;}
  76. else
  77. {i%2==1? a.push_back (dob):b.push_back (dob);} // Oi Arties Times apoteloun ta a, oi perites ta b
  78. }
  79.  
  80. }
  81.  
  82. }// Ypologizontas ta Q(j)
  83. for (j=0;j<=c;j++)
  84. {
  85. q.push_back(Qj(k,j,a,b));
  86. sum=sum+Qj(k,j,a,b);
  87. }
  88.  
  89. for (i=0;i<q.size();i++)
  90. {
  91. q[i]=(q[i]/sum);
  92. cout<<q[i]<<"\t";
  93. }
  94.  
  95. cout<<endl<<"k is "<<k<<"\t"<<"and C is "<<c<<endl;
  96.  
  97. for (cat=0;cat<k;cat++)
  98. {r.clear();
  99. for (jj=0;jj<=c;jj++)
  100. {r.push_back(Yj(cat,jj,a,b,q));}
  101.  
  102. yj.push_back(r);}
  103.  
  104.  
  105.  
  106. for (int q=0;q<k;q++){
  107. for (int qq=0;qq<=c;qq++)
  108. {cout<<yj[q][qq]<<"\t";}}
  109.  
  110.  
  111. input_File.close();
  112. cin >> line;
  113.  
  114. return 0 ;
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement