#include using namespace std; const int Max = 50; int Grid[Max][Max][2]; int Table[10][Max][Max][2]; int CountTable[10][Max][Max]; int lastName, caseNo=1; string name1, name2; int n, m, pos1, pos2, no1, no2; string Names[Max]; int bestCount, numerator, denominator; void PrintTable(int k){ cout<<"Table "< n2*Table[1][pos1][pos2][0]){ Table[1][pos1][pos2][0] = n1; Table[1][pos1][pos2][1] = n2; CountTable[1][pos1][pos2] = 1; } else if(n1*Table[1][pos1][pos2][1] == n2*Table[1][pos1][pos2][0]) //duplicate CountTable[1][pos1][pos2]++; } void CreateTables(){ //Table[*][i][j] = best rate for j->i in exactly * steps int tab1, tab2, num, den; for(int tab=2; tab<10; tab++) { //create Table[tab] for(int i=0;i den*Table[tab][i][j][0]){ CountTable[tab][i][j] = CountTable[tab1][i][k] * CountTable[tab2][k][j]; Table[tab][i][j][0] = num; Table[tab][i][j][1] = den; } else if(num*Table[tab][i][j][1] == den*Table[tab][i][j][0]) //tie - add counts CountTable[tab][i][j] += CountTable[tab1][i][k] * CountTable[tab2][k][j]; } } } } } //return position of N in Names[0..lastName] - insert at end if not in table int namePos(string N){ for(int i=0;i=1){ left=0; while(x>=1){ x /= 10; left++; } // move x left 5 digits x *= 100000; p=int (x); y = x-p; if(y >= 0.5 - 0.000001) p++; //p has the 5 sig digits, so print if(left>=5){ cout<=0.5) p++; //p now holds 5 sig digits // print 0's for(int i=0;i> n; for(int i=0;i>name1>>name2>>m; init(m); Names[0]=name1; Names[1]=name2; //enter the one-step table for(int j=0;j>no1>>name1>>no2>>name2; pos1 = namePos(name1); pos2 = namePos(name2); AddToGrid(no1, pos1, no2, pos2); } CreateTables(); //PrintTable(1); //PrintCountTable(1); //PrintTable(2); //PrintCountTable(2); //PrintTable(6); //PrintTable(8); //find best ratio in Table[*][0][1] best = 1; bestCount = CountTable[1][0][1]; for(int k=2;k<10;k++){ /* cout<<"in for loop, k= "<