Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<locale.h>
- #define INPUT "input.txt"
- #define OUTPUT "output.txt"
- using namespace std;
- struct Word
- {
- char ch = 0;
- Word* next;
- };
- struct Line
- {
- int count = 0;
- Word* word;
- Line* next;
- };
- void search(Line* line, int find)
- {
- Word* wordNow;
- wordNow = line->word->next;
- while (wordNow != NULL)
- {
- if (((int(wordNow->ch))%2)==find)
- line->count++;
- cout << wordNow->ch;
- wordNow = wordNow->next;
- }
- cout << "<-" << "\n";
- cout << line->count << "\n";
- }
- void main()
- {
- setlocale(LC_ALL, "Russian");
- char ch = 0;
- int find;
- bool point = false;
- fstream file;
- file.open(INPUT);
- if (file.is_open())
- {
- cout << "Четное или нечетное: ";
- cin >> find;
- find = find % 2;
- Line lineFirst;
- Line* lineNow;
- lineNow = &lineFirst;
- lineFirst.word = new Word;
- Word* wordNow = lineFirst.word;
- while ((!file.eof()) && (ch != '.'))
- {
- ch = file.get();
- if (ch == '.') point = true;
- if ((ch != ' ') && (ch != '.'))
- {
- wordNow->next = new Word;
- wordNow = wordNow->next;
- wordNow->ch = ch;
- }
- else if (wordNow->ch != 0)
- {
- lineNow->next = new Line;
- lineNow = lineNow->next;
- lineNow->word = new Word;
- wordNow->next = NULL;
- wordNow = lineNow->word;
- }
- }
- file.close();
- wordNow->next = NULL;
- lineNow->next = NULL;
- if (point == true)
- {
- file.open(OUTPUT, ios_base::out | ios_base::trunc);
- if (file.is_open())
- {
- if (lineFirst.word->next != NULL)
- {
- lineNow = &lineFirst;
- while (lineNow->next != NULL)
- {
- search(lineNow, find);
- file << lineNow->count << " ";
- lineNow = lineNow->next;
- }
- }
- else
- {
- cout << "File is empty!\n";
- }
- file.close();
- }
- else
- {
- cout << "Output file not found!\n";
- }
- }
- else
- {
- cout << "Point not found!\n";
- }
- }
- else {
- cout << "Input file not found!\n";
- }
- cin >> ch;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement