UVA Solution 436 - Arbitrage (II) - Solution in C, C++ - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Thursday, May 11, 2017

UVA Solution 436 - Arbitrage (II) - Solution in C, C++

UVA Solution 436 - Arbitrage (II) - Solution in C, C++


UVA Online Judge Solution 436 - Arbitrage (II) | Volume 4
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=377

Problem Name: 436 - Arbitrage (II)
Problem Number : UVA - 436 - Arbitrage (II)
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : C, C plus plus

UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list

UVA Solution 436 - Arbitrage (II) Code in C, CPP:

#include <stdio.h>
#include <string.h>
char dollar[31][50], a[50], b[50];
int encode(char s[]) {
    int i;
    for(i = 0; ; i++) {
        if(!strcmp(dollar[i], s))
            return i;
    }
}
int main() {
    int n, m, test = 0;
    int i, j, k;
    while(scanf("%d", &n) == 1 && n) {
        double map[31][31] = {}, f;

        for(i = 0; i < n; i++)
            scanf("%s", dollar[i]), map[i][i] = 1;
        scanf("%d", &m);

        while(m--) {
            scanf("%s %lf %s", a, &f, b);
            i = encode(a);
            j = encode(b);
            map[i][j] = f;
        }
        for(k = 0; k < n; k++) {
            for(i = 0; i < n; i++) {
                for(j = 0; j < n; j++) {
                    if(map[i][j] < map[i][k]*map[k][j])
                        map[i][j] = map[i][k]*map[k][j];
                }
            }
        }
        int flag = 0;
        for(i = 0; i < n; i++)
            if(map[i][i] > 1 + 1e-5)
                flag = 1;
        printf("Case %d: %s\n", ++test, flag ? "Yes" : "No");
    }
    return 0;
}


Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA 436 - Arbitrage (II)  Problems Solution, UVA Arbitrage (II)  solver, UVA all problem solution list, UVA 436  code in C, UVA Arbitrage (II)   code in C++, UVA 436 solution in C, UVA 436 solution

No comments:

Post a Comment