#include #include #include using namespace std; struct strCmp { bool operator()( const char* s1, const char* s2 ) const { return strcmp( s1, s2 ) < 0; } }; struct Node { char nazev[5]; int nextCount; Node * next[200]; double nextNasobitel[200]; double nasobitel; }; Node nodes[200]; int nodesCount = 0; int loadNazvy() { scanf("%d", &nodesCount); if(nodesCount == 0) return 0; map meny; for(int i = 0; i < nodesCount; i++) { scanf("%s", nodes[i].nazev); meny[nodes[i].nazev] = &nodes[i]; nodes[i].nasobitel = -1; // nulování nodes[i].nextCount = 0; } int hran; char nazev1[5]; char nazev2[5]; int jmenovatel; int citatel; Node * current; scanf("%d", &hran); for(int i = 0; i < hran; i++) { scanf("%s %s %d:%d", nazev1, nazev2, &jmenovatel, &citatel); current = meny[nazev1]; current->next[current->nextCount] = meny[nazev2]; current->nextNasobitel[current->nextCount] = (double)citatel / jmenovatel; current->nextCount++; } /*for(int i = 0; i < nodesCount; i++) { printf("Node %s hran=%d\n", nodes[i].nazev, nodes[i].nextCount); for(int j = 0; j < nodes[i].nextCount; j++) { printf(" na %s nasobitel %lf\n", nodes[i].next[j]->nazev, nodes[i].nextNasobitel[j]); } }*/ return 1; } int pocitej() { for(int gl = 0; gl < nodesCount; gl++) { Node * start = &nodes[gl]; start->nasobitel = 1.0f; //int pocetNedosazeno = nodesCount; int pocetDosazeno = 1; //Node* nedosazeno[200]; Node* dosazeno[200]; dosazeno[0] = start; //Node* hotovo[200]; for(int i = 0; i < nodesCount; i++) { if(gl != i) { nodes[i].nasobitel = -1; // nedosazeno[i] = &nodes[i]; } } while(pocetDosazeno > 0) { pocetDosazeno--; Node * current = dosazeno[pocetDosazeno]; for(int i = 0; i < current->nextCount; i++) { float hodnota = current->nasobitel * current->nextNasobitel[i]; if(current->next[i]->nasobitel < hodnota) { current->next[i]->nasobitel = hodnota; dosazeno[pocetDosazeno] = current->next[i]; pocetDosazeno++; if(current->next[i] == start) return 1; } } } } return 0; } int main() { while(loadNazvy()) { //printf("\n\n"); /*if(pocitej()) printf("Arbitrage\n"); else printf("Ok\n");*/ } return 0; }