Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #define _CRT_SECURE_NO_WARNINGS
- using namespace std;
- void fillingAnArrayOfWords(ifstream*, string*, int*);
- void outputToTheConsoleAnArrayOfWords(string*, int*);
- void arrayReset(int*, int*);
- void numberOfSubwords(string*, int*, int*);
- void arrayOutput(ofstream*, int*, int*);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n;
- ifstream in("D:\\Users\\Nevarkir\\source\\repos\\Project1\\Project1\\6b\\input.txt");
- in >> n;
- string* c;
- c = new string[n];
- fillingAnArrayOfWords(&in, c, &n);
- //cout << "\n" << endl;
- //outputToTheConsoleAnArrayOfWords(c, &n);
- in.close();
- int* a;
- a = new int[n];
- arrayReset(a, &n);
- numberOfSubwords(c, a, &n);
- ofstream out;
- out.open("D:\\Users\\Nevarkir\\source\\repos\\Project1\\Project1\\6b\\output.txt");
- arrayOutput(&out, a, &n);
- out.close();
- delete[] c;
- delete[] a;
- system("PAUSE");
- return 0;
- }
- void fillingAnArrayOfWords(ifstream* in, string* c, int* n)
- {
- for (int i = 0; i < (*n); i++)
- {
- (*in) >> c[i];
- }
- }
- void outputToTheConsoleAnArrayOfWords(string* c, int* n)
- {
- for (int i = 0; i < (*n); i++)
- {
- cout << c[i] << endl;
- }
- }
- void arrayReset(int* a, int* n)
- {
- for (int i = 0; i < (*n); i++)
- {
- a[i] = 0;
- }
- }
- void numberOfSubwords(string* c, int* a, int* n)
- {
- for (int i = 0; i < (*n); i++)
- {
- for (int j = 0; j < (*n); j++)
- {
- if (i != j)
- {
- //cout << "=============================================================================================" << endl;
- //cout << "START: В слове - " << c[i] << " под номером " << i << " при сравнении со словом - " << c[j] << " под номером " << j << ". Значение a[" << i << "] = " << a[i] << endl;
- int m1 = c[i].length();
- char* s1;
- s1 = new char[m1];
- strcpy(s1, c[i].c_str());
- //cout << s1 << " с длиной: " << m1 << endl;
- int m2 = c[j].length();
- char* s2;
- s2 = new char[m2];
- strcpy(s2, c[j].c_str());
- //cout << s2 << " с длиной: " << m2 << endl;
- int count = 0;
- for (int k = 0; k < m2; k++)
- {
- if (k + m1 - 1 < m2)
- {
- if (s2[k] == s1[0])
- {
- count = 0;
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- //cout << "Начат процесс сравнения: " << endl;
- for (int h = 0; h < m1; h++)
- {
- if (s2[k + h] == s1[h]) count++;
- //cout << k + h << ": " << s2[k + h] << " и " << h << ": " << s1[h] << endl;
- }
- //cout << "Сравнение завершено" << endl;
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- if (count == m1)
- {
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- //cout << "Слова совпали" << endl;
- a[i]++;
- //cout << a[i] << endl;
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- }
- else
- {
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- //cout << "Слова не совпали" << endl;
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- }
- }
- }
- else
- {
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- //cout << "Длины не совпали" << endl;
- //cout << "---------------------------------------------------------------------------------------------" << endl;
- }
- }
- //cout << "END: В слове - " << c[i] << " под номером " << i << " при сравнении со словом - " << c[j] << " под номером " << j << ". Значение a[" << i << "] = " << a[i] << endl;
- }
- }
- }
- }
- void arrayOutput (ofstream* out, int* a, int* n)
- {
- for (int i = 0; i < (*n); i++)
- {
- (*out) << a[i] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement