Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <queue>
- #include <vector>
- #include <string>
- using namespace std;
- ofstream fout ("output.txt");
- vector <queue <int> > vec;
- int Function (string func){
- if (func[0]=='P'){
- if (func[1]=='U')
- return 0; //PUSH
- else
- return 1; //POP
- }
- else
- return -1; // TOP
- }
- pair<int,int> GetIndex(string func){
- if (!Function(func)){
- int i = 6;
- int ans = (func[5]-'0');
- while ( func[i] != ',' ){
- ans *= 10;
- ans += (func[i] - '0');
- i++;
- }
- i+=2;
- int post = (func[i-1] - '0');
- while ( func[i] != ')' ){
- post *= 10;
- post += (func[i] - '0');
- i++;
- }
- return make_pair(ans,post);
- }
- else {
- int i = 5;
- int ans = (func[4]-'0');
- while ( func[i] != ')' ){
- ans *= 10;
- ans += (func[i] - '0');
- i++;
- }
- return make_pair(ans,0);
- }
- }
- inline void inter (string func){
- if (!Function(func)){
- vec[GetIndex(func).first-1].push(GetIndex(func).second);
- }
- else if(Function(func) > 0){
- int index = GetIndex(func).first-1;
- fout << vec[index].front() << " ";
- vec[index].pop();
- }
- else {
- fout << vec[GetIndex(func).first-1].front() << " ";
- }
- }
- int main(){
- ifstream fin ("input.txt");
- int n, k;
- fin >> n >> k;
- vec = vector <queue <int> > (n);
- string func;
- getline(fin,func);
- for (int i = 0 ; i < k; i++){
- getline(fin,func);
- inter (func);
- }
- fin.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement