So my code:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <bits/stdc++.h>
#include <utility>
using namespace std;
int x, y, g;
void solve() {
cin >> x;
vector<pair<string, string>> CanBe(x);
for (int i = 0; i < x; i++) {
string a, b;
cin >> a >> b;
CanBe.push_back({a, b});
}
cin >> y;
vector<pair<string, string>> CantBe(y);
for (int i = 0; i < y; i++) {
string a, b;
cin >> a >> b;
CantBe.push_back({a, b});
}
cin >> g;
int totalViolations = 0;
unordered_map<string, int> nameToGroup;
//vector<vector<string>> groups(g, vector<string>(3));
for (int i = 0; i < g; i++) {
string a, b, c;
cin >> a >> b >> c;
nameToGroup[a] = i;
nameToGroup[b] = i;
nameToGroup[c] = i;
}
for (int i = 0; i < x; i++) {
pair<string, string> restriction = CanBe[i];
cout << restriction.first << " CHECK CAN " << restriction.second << endl;
if (nameToGroup[restriction.first] != nameToGroup[restriction.second]) {
totalViolations++;
cout << restriction.first << " CANBE " << restriction.second << endl;
}
}
for (int i = 0; i < y; i++) {
pair<string, string> restriction = CantBe[i];
cout << restriction.first << " CHECK CANT " << restriction.second << endl;
if (nameToGroup[restriction.first] == nameToGroup[restriction.second]) {
totalViolations++;
cout << restriction.first << " CANTBE " << restriction.second << endl;
}
}
cout << totalViolations;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
for this problem right here, https://dmoj.ca/problem/ccc22s2
I ran into an issue where the lines where im printing cout << restriction.first << " CHECK CANT " << restriction.second << endl; prints out empty strings eg CHECK CANT rather than BILLY CHECK CANT BOB. i'm sure it's some kind of semantic issue but i cant figure it out
DMOJ: Modern Online Judge
A class has been divided into groups of three. This division into groups might violate two types of constraints: some students must work together in the same group, and some students must work in separate groups.