Here is my code for which I’m getting a SIGSEGV error:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
stack<string> st;
string min_book;
int min_weight = INT_MAX;
while(t--){
int num, i;
cin >> num;
if(num != -1){
string s;
cin >> s;
st.push(s);
if(min_book.empty()){
min_book = s;
min_weight = num;
}
else if(num <= min_weight){
min_book = s;
min_weight = num;
}
}else{
int cnt = 0;
while(!st.empty() || st.top() != min_book){
st.pop();
cnt += 1;
}
cout << cnt << " " << min_book << "\n";
}
}
return 0;
}