Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #define INPUT "input.txt"
- #define OUTPUT "output.txt"
- using namespace std;
- struct Symbol
- {
- char ch;
- Symbol* next = NULL;
- };
- bool check(Symbol* firstSymbol)
- {
- bool dlt = false;
- Symbol* nowSymbol = firstSymbol, * buf;
- while (nowSymbol->next != NULL)
- {
- if (nowSymbol->next->ch == firstSymbol->ch)
- {
- dlt = true;
- buf = nowSymbol->next->next;
- delete(nowSymbol->next);
- nowSymbol->next = buf;
- }
- else
- nowSymbol = nowSymbol->next;
- }
- return dlt;
- }
- void main()
- {
- char ch;
- bool empty = true;
- fstream file;
- file.open(INPUT);
- if (file.is_open())
- {
- Symbol* firstSymbol = new Symbol, * nowSymbol = firstSymbol, *buf;
- while (!file.eof())
- {
- ch = file.get();
- if ((ch != ' ') && (ch != EOF))
- {
- cout << ch << "\n";
- nowSymbol->next = new Symbol;
- nowSymbol = nowSymbol->next;
- nowSymbol->ch = ch;
- empty = false;
- }
- }
- if (empty != true)
- {
- cout << "_____________ \n";
- file.close();
- file.open(OUTPUT, ios_base::out | ios_base::trunc);
- if (file.is_open())
- {
- nowSymbol = firstSymbol;
- while (nowSymbol->next != NULL)
- {
- if (check(nowSymbol->next))
- {
- buf = nowSymbol->next->next;
- delete(nowSymbol->next);
- nowSymbol->next = buf;
- }
- else
- {
- cout << nowSymbol->next->ch << "\n";
- file << nowSymbol->next->ch << " ";
- nowSymbol = nowSymbol->next;
- }
- }
- file.close();
- }
- else
- {
- cout << "Output file not found!\n";
- }
- }
- else
- cout << "File is empty!\n";
- }
- else {
- cout << "Input file not found!\n";
- }
- cin >> ch;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement