Advertisement
Norbi930523

alternatív tabella

Apr 14th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. void rendez(string csapat[16],int ep[16],string csapatKereszt[16],double hv[16]){
  7.     double tmp[16];
  8.     for(int i=0;i<16;i++){
  9.         tmp[i]=hv[i];
  10.     }
  11.     int index[16];
  12.  
  13.     for(int j=0;j<16;j++){
  14.         int maxindex=0;
  15.         for(int i=1;i<16;i++){
  16.             if(tmp[i]>tmp[maxindex]){
  17.                 maxindex=i;
  18.             }
  19.         }
  20.         index[j]=maxindex;
  21.         tmp[maxindex]=0;
  22.     }
  23.  
  24.     for(int i=0;i<16;i++){
  25.         cout << csapat[i] << "\t" << ep[i] << "\t" << csapatKereszt[index[i]] << "\t" << hv[index[i]] << endl;
  26.     }
  27.  
  28. }
  29.  
  30. void wiki2matrix(int kereszt[16][16],int pont[16][16],int oszloposszeg[16],double L[16][16]){
  31.     int i,j;
  32.     for(i=0;i<16;i++)
  33.         for(j=0;j<16;j++){
  34.             if(kereszt[i][j]==1)
  35.                 ++pont[i][j];
  36.             else if(kereszt[i][j]==2){
  37.                 ++pont[i][j];
  38.                 ++pont[j][i];
  39.             }
  40.             else if(kereszt[i][j]==3)
  41.                 ++pont[j][i];
  42.         }
  43.  
  44.     cout << "Az X pontot szerez Y-tol matrix:" << endl;
  45.  
  46.     for(i=0;i<16;i++){
  47.         for(j=0;j<16;j++){
  48.             cout << pont[i][j] << " ";
  49.         }
  50.         cout << endl;
  51.     }
  52.     cout << endl;
  53.     cout << "Sor és oszlop összegekkel:" << endl;
  54.  
  55.     for(i=0;i<16;i++){
  56.         int o=0;
  57.         for(j=0;j<16;j++){
  58.             cout << pont[i][j] << "\t";
  59.             o+=pont[i][j];
  60.         }
  61.         cout << o << endl;
  62.     }
  63.     for(i=0;i<16;i++){
  64.         int o=0;
  65.         for(j=0;j<16;j++){
  66.             o+=pont[j][i];
  67.         }
  68.         cout << o << "\t";
  69.         oszloposszeg[i]=o;
  70.     }
  71.     cout << endl;
  72.     cout << "A linkmatrix" << endl;
  73.    
  74.     for(i=0;i<16;i++){
  75.         cout << "{";
  76.         for(j=0;j<16;j++){
  77.             if(oszloposszeg[j]!=0){
  78.                 cout << (double)(pont[i][j]*(1.0/oszloposszeg[j])) << ", ";
  79.                 L[i][j]=(double)(pont[i][j]*(1.0/oszloposszeg[j]));
  80.             }
  81.             else{
  82.                 cout << pont[i][j] << ", ";
  83.                 L[i][j]=pont[i][j];
  84.             }
  85.         }
  86.         cout << "}," << endl;
  87.     }
  88. }
  89.  
  90. int main(){
  91.     int kereszt[16][16]={
  92.         {0, 2, 1, 0, 0, 0, 2, 1, 0, 0, 3, 2, 3, 1, 2, 3},
  93.         {1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 3, 3, 1, 0, 3, 1},
  94.         {1, 0, 0, 1, 0, 3, 2, 3, 0, 0, 1, 1, 2, 1, 1, 1},
  95.         {3, 1, 3, 0, 2, 0, 3, 0, 3, 2, 3, 2, 0, 2, 0, 3},
  96.         {3, 1, 1, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 1, 0},
  97.         {2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 0, 0, 1, 1, 1, 0},
  98.         {0, 0, 2, 1, 2, 2, 0, 2, 0, 0, 1, 3, 2, 1, 1, 3},
  99.         {0, 1, 0, 2, 1, 3, 0, 0, 3, 1, 2, 0, 2, 1, 2, 3},
  100.         {1, 2, 2, 0, 2, 0, 1, 3, 0, 3, 2, 0, 3, 0, 0, 0},
  101.         {1, 1, 2, 0, 3, 0, 1, 1, 3, 0, 3, 2, 3, 0, 0, 1},
  102.         {1, 0, 0, 1, 1, 3, 0, 1, 1, 1, 0, 0, 2, 2, 1, 1},
  103.         {3, 0, 0, 3, 0, 2, 2, 3, 0, 1, 2, 0, 3, 1, 2, 2},
  104.         {0, 3, 0, 2, 2, 3, 0, 3, 3, 0, 1, 3, 0, 1, 3, 2},
  105.         {3, 3, 0, 1, 2, 3, 3, 0, 3, 1, 0, 2, 0, 0, 0, 3},
  106.         {0, 2, 2, 1, 1, 0, 0, 1, 1, 2, 0, 3, 0, 1, 0, 3},
  107.         {3, 1, 2, 1, 3, 3, 1, 0, 1, 2, 0, 0, 0, 1, 2, 0}};
  108.     int pont[16][16];
  109.     int oszloposszeg[16];
  110.     int i,j;
  111.     double L[16][16];
  112.     for(i=0;i<16;i++){
  113.         for(j=0;j<16;j++){
  114.             pont[i][j]=0;
  115.         }
  116.     }
  117.     wiki2matrix(kereszt,pont,oszloposszeg,L);
  118.  
  119.     string csapat[16]={"Győri ETO","MTK Budapest","Videoton","Ferencváros","Debreceni VSC","Diósgyőr","Budapest Honvéd","Kaposvári Rákóczi","Paksi FC","Újpest","Kecskeméti TE","Haladás","Pécsi MFC","Lombard Pápa","Egri FC","BFC Siófok"};
  120.  
  121.     int ep[16]={50,41,38,35,33,31,29,29,29,28,27,27,25,23,12,10};
  122.  
  123.     string csapatKereszt[16]={"Budapest Honvéd","Debreceni VSC","Diósgyőr","Egri FC","Ferencváros","Győri ETO","Haladás","Kaposvári Rákóczi","Kecskeméti TE","Lombard Pápa","MTK Budapest","Paksi FC","Pécsi MFC","BFC Siófok","Újpest","Videoton"};
  124.  
  125.     double hv[16], h[16];
  126.  
  127.     for(i=0;i<16;i++){
  128.         hv[i]=1.0/16;
  129.         h[i]=0.0;
  130.     }
  131.    
  132.     double reginorma = 0.0, regiosszeg = 0.0;
  133.     bool amig=true;
  134.  
  135.     while(amig){
  136.         for(i=0;i<16;i++){
  137.             for(j=0;j<16;j++){
  138.                 h[i]+= L[i][j] * hv[j];
  139.             }
  140.             cout << h[i] << endl;
  141.         }
  142.        
  143.         double osszeg = 0.0;
  144.  
  145.         for(i=0;i<16;i++){
  146.             osszeg += (hv[i] - h[i]) * (hv[i] - h[i]);
  147.         }
  148.  
  149.         double norma = sqrt(osszeg);
  150.         cout << "Norma= " << norma << endl;
  151.  
  152.         if(norma < 0.000000000001){
  153.             amig = false;
  154.             cout << endl;
  155.             double osszegEll = 0.0;
  156.             for (int i = 0; i < 16; ++i) {
  157.                 osszegEll += h[i];
  158.             }
  159.             cout << "osszegell = " << osszegEll << endl;
  160.         }
  161.  
  162.         double d=0.87;
  163.         osszeg=0.0;
  164.  
  165.         for (int i = 0; i < 16; ++i) {
  166.             hv[i] = d * h[i] + (1.0 - d) / 16;
  167.             osszeg += hv[i];
  168.             h[i] = 0.0;
  169.         }
  170.  
  171.         cout << "osszeg: " << osszeg << endl;
  172.  
  173.         if (osszeg == regiosszeg && norma == reginorma){
  174.             amig = false;
  175.  
  176.             for (int i = 0; i < 16; ++i) {
  177.                 cout << hv[i] << endl;
  178.             }
  179.         }
  180.         reginorma = norma;
  181.         regiosszeg = osszeg;
  182.     }
  183.     rendez(csapat,ep,csapatKereszt,hv);
  184.  
  185.     return 0;
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement