#Printing out pair elements is empty

7 messages · Page 1 of 1 (latest)

dusty bloom
#

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

half lanceBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

dusty bloom
#

i'm just debugging

#

i'm really clueless as to what's causing this 😭

dusty bloom
#

alright nvm, i initialized the size of the array

#

and pushed back to the array

#

so whenever i loop through it, it loops through empty values