11995 - I Can Guess the Data Structure!

All about problems in Volume 119. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

bitaron
New poster
Posts: 12
Joined: Mon Jan 06, 2014 9:40 pm

Re: 11995 - I Can Guess the Data Structure!

Post by bitaron » Sun Oct 04, 2015 5:18 pm

Runtime error. Please help

Code: Select all

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;


set<string> removeElement(set<string> ans, string item){
	for (std::set<string>::iterator it=ans.begin(); it!=ans.end(); ++it){
		if(*it == item){
			ans.erase(*it);
		}
	}
	return ans;
}

int main(int argc, char **argv)
{
	//cout<<"here";
	int n,type,data;
	vector<int> in,out;
	std::ifstream infile;
	ofstream outfile;
	//outfile.open("12372Output.txt");
	//infile.open("11995Input.txt");
	//infile>>caseNumber;
	//cin>>caseNumber;
	
	while(1){
		stack<int> s;
		queue<int> q;
		priority_queue<int>pq;
		set<string> ans;
		vector<bool> status(3,true);
		//infile>>n;
		cin>>n;
		if(cin.eof()){
			break;
		}
		//cout<<n;
		//cin>>n;
		for(int i=0; i<n;i++){
			//infile>>type;
			//infile>>data;
			cin>>type;
			cin>>data;
			if(type == 1){
				s.push(data);
				q.push(data);
				pq.push(data);
			}else{
				if(s.top() == data && status[0]){
					ans.insert("stack");
					if(!s.empty()){
						s.pop();
					}
				}else{
					status[0] = false;
					ans=removeElement(ans,"stack");
				}
				if(q.front() == data && status[1]){
					ans.insert("queue");
					if(!q.empty()){
						q.pop();
					}
					
				}else{
					status[1] = false;
					ans=removeElement(ans,"queue");
				}
				if(pq.top() == data && status[2]){
					
					ans.insert("priority queue");
					if(!pq.empty()){
						pq.pop();
					}
				}else{
					status[2] = false;
					ans=removeElement(ans,"priority queue");
				}
			}
			
		}
		
		string fa;
		if(ans.empty()){
			fa = "impossible";
		}else{
			if(ans.size() >1){
				fa =  "not sure";
			//	cout<<*ans.begin()<<" "<<*(++ans.begin());
			}else{
				fa = *ans.begin();
			}
	}
		cout<<fa<<"\n";
		
		
	}

	return 0;
}



Post Reply

Return to “Volume 119 (11900-11999)”