USACO 2021 February Contest, Bronze
Problem 1. Year of the cow
https://usaco.org/index.php?page=viewproblem2&cpid=1107
#include<bits/stdc++.h>
using namespace std;
int main()
{
map<string, pair<int, int>> relationship_to_ox = {
{"Ox", make_pair(12, 12)},
{"Tiger", make_pair(11, 1)},
{"Rabbit", make_pair(10, 2)},
{"Dragon", make_pair(9, 3)},
{"Snake", make_pair(8, 4)},
{"Horse", make_pair(7, 5)},
{"Goat", make_pair(6, 6)},
{"Monkey", make_pair(5, 7)},
{"Rooster", make_pair(4, 8)},
{"Dog", make_pair(3, 9)},
{"Pig", make_pair(2, 10)},
{"Rat", make_pair(1, 11)}
}; // animal : (before ox, after ox)
map<string, int> cow_data; // animal : years from bessie
int n;
cin>>n;
for(int i=0;i<n;i++)
{
// get input and split
string line;
getline(cin, line);
string word = "";
vector<string> words;
for(int j=0;j<line.length();j++)
{
if(line[j] == ' ')
{
words.push_back(word);
word = "";
}
else
word += line[j];
}
// useful data
string first_cow = words[0];
string relationship = words[3];
string animal = words[4];
string seconds_cow = words[7];
}
return 0;
}
I am getting a segmentation error in vscode, I think it has something to do with the getline function. Can something help me?