<jupyter_start><jupyter_text>Pilas!<jupyter_code>%%writefile stack.h
#ifndef __PILA_H__
#define __PILA_H__

template <typename T>
class Stack {
    struct Node {
        T e; Node* next;
        Node(T e, Node* next=nullptr) : e(e), next(next) {}
    };

    Node*   _top;
    int     len;
public:
    Stack() : _top(nullptr), len(0) {}
    ~Stack() {
        while (_top != nullptr) {
            Node* aux = _top;
            _top = _top->next;
            delete aux;
        }
    }
    int     size()  { return len; }
    bool    empty() { return len == 0; }

    void    push(T e) {
        _top = new Node(e, _top);
        ++len;
    }
    void    pop() {
        if (len > 0) {
            Node* aux = _top;
            _top = _top->next;
            delete aux;
            --len;
        }
    }
    T       top() {
        if (len > 0) {
            return _top->e;
        }
        return 0;
    }
};

#endif
%%writefile post.cpp
#include <iostream>
#include <string>
#include "stack.h"

using namespace std;

int main() {
    Stack<float> operands;
    float a, b, r;
    string term;
    cout << "Expresión: ";
    for (;;) {
        cin >> term;
        if (term == ".") {
            break;
        } else {
            if ((term[0] >= '0' && term[0] <= '9') ||
                (term[0] == '-' && term.size() > 1)) {
                operands.push(stof(term));
            } else {
                b = operands.top(); operands.pop();
                a = operands.top(); operands.pop();
                switch (term[0]) {
                    case '+': r = a + b; break;
                    case '-': r = a - b; break;
                    case '*': r = a * b; break;
                    case '/': r = a / b; break;
                }
                operands.push(r);
            }
        }
    }
    cout << operands.top() << endl;
    operands.pop();
    return 0;
} 
%%writefile input.in
-12 78 23 47 -2334 / * 34 - / + .
!g++ -std=c++14 post.cpp && ./a.out < input.in
-12 + (78 / ((23 * (47 / -2334 )) - 34))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16626154594069031, 'fraction_numerical': 0.020904229460379193, 'mean_word_length': 1.2994413407821228, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '377611', 'license': 'CC0-1.0', 'n_tokens_mistral': 747, 'n_tokens_neox': 707, 'n_words': 176, 'path': '20202/aed_20202_0503_postfixed_calc.ipynb', 'repo_name': 'pcsilcan/aed', 'size': '2057'}