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");
- class Stack {
- struct slovos {
- string wrd;
- slovos *next;
- slovos(string x, slovos *p) : wrd(x), next(p){}
- };
- slovos* head;
- public:
- Stack() : head(0){}
- bool Empty() { //проверка на пустоту стека
- return head == 0;
- }
- void Push(string data) { // добавляем элемент
- head = new slovos(data, head);
- }
- string Top() {
- return head->wrd;
- }
- string Pop() {
- slovos* r = head;
- string i = r->wrd;
- head = r->next;
- delete r;
- return i;
- }
- };
- int main() {
- Stack 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