UVA Solution 334 - Identifying Concurrent Events - Solution in C, C++ | Volume 3 - 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

Friday, May 5, 2017

UVA Solution 334 - Identifying Concurrent Events - Solution in C, C++ | Volume 3

UVA Solution 334 - Identifying Concurrent Events - Solution in C, C++ | Volume 3


UVA Online Judge Solution 300 - Stacks | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=270

Problem Name: 334 - Identifying Concurrent Events
Problem Number : UVA - 334 - Identifying Concurrent Events
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 334 - Identifying Concurrent Events - Solution in C, C++ | Volume 3

UVA Solution 334 - Identifying Concurrent Events Code in C, CPP:


#include <stdio.h>
#include <vector>
#include <map>
#include <iostream>
using namespace std;

int main() {
    int n, m, cases = 0, i, j, k;
    while(scanf("%d", &n) == 1 && n) {
        int g[105][105] = {};
        vector<string> Rv;
        map<string, int> R;
        string x, y;
        for(i = 0; i < 105; i++)
            for(j = 0; j < 105; j++)
                g[i][j] = 0;
        int idx = 0;
        for(i = 0; i < n; i++) {
            scanf("%d", &m);
            int pre = idx;
            for(j = 0; j < m; j++) {
                cin >> x;
                R[x] = idx, Rv.push_back(x);
                idx++;
            }
            for(j = pre; j < idx-1; j++)
                g[j][j+1] = 1;
        }
        scanf("%d", &m);
        while(m--) {
            cin >> x >> y;
            g[R[x]][R[y]] = 1;
        }
        for(k = 0; k < idx; k++)
            for(i = 0; i < idx; i++)
                for(j = 0; j < idx; j++)
                    g[i][j] |= g[i][k]&g[k][j];

        string res = "";
        int cnt = 0;
        for(i = 0; i < idx; i++)
            for(j = i+1; j < idx; j++)
                if(g[i][j] == 0 && g[j][i] == 0) {
                    cnt++;
                    if(cnt <= 2) {
                        res = res+"("+Rv[i]+","+Rv[j]+") ";
                    }
                }
        if(cnt) {
            printf("Case %d, %d concurrent events:\n", ++cases, cnt);
            cout << res << endl;
        } else
            printf("Case %d, no concurrent events.\n", ++cases);
    }
    return 0;
}

No comments:

Post a Comment