Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- template <class T>
- class Stack {
- struct node {
- T data;
- node *next;
- node(string x, node *p) : data(x), next(p){}
- };
- node* head;
- public:
- Stack() : head(0){}
- bool Empty() { //проверка на пустоту стека
- return head == 0;
- }
- void Push(T data) { // добавляем элемент
- head = new node(data, head);
- }
- T Top() {
- return head->data;
- }
- T Pop() {
- node* r = head;
- head = head->next;
- T g = r->data;
- delete r;
- return g;
- }
- };
- int main() {
- Stack <string> t, t1;
- string s;
- while (in >> s) {
- t.Push(s);
- }
- in.close();
- while (!t.Empty()) {
- string i = t.Pop();
- t1.Push(i);
- if (i.size() == 1) {
- t1.Push(i);
- }
- }
- while (!t1.Empty()) {
- out << t1.Pop() << endl;
- }
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement