Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <string>
- #include <iomanip>
- using namespace std;
- string answers[1000];
- string same_words[100][100];
- int counter = 0;
- int amount_of_words[100];
- void change_str(string str) {
- string answer = "";
- int word_length = 0;
- for (char& a : str) {
- if ((a >= 'a' && a <= 'z') || (a == ' ') || (a >= 'A' && a <= 'Z') || (a >= '0' && a <= '9')) {
- if (a != ' ')
- word_length++;
- if (a >= 'A' && a <= 'Z') {
- char ch((int)a + 32);
- answer += ch;
- }
- else
- answer += a;
- }
- if (a == ' ') {
- // cout << answer << " " << word_length << endl;
- if (word_length <= 3) {
- for (int j = 0; j <= word_length; j++)
- answer.pop_back();
- }
- word_length = 0;
- }
- }
- // это нормализация
- answers[counter] = answer;
- int word_counter = 0;
- string word = "";
- for (char&a : answer) {
- if (a != ' ')
- word += a;
- else if (a == ' ') {
- same_words[counter][word_counter] = word;
- word = "";
- word_counter++;
- }
- // здесь двумерный массив из слов создается
- }
- same_words[counter][word_counter] = word;
- amount_of_words[counter] = word_counter;
- counter++;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- char a;
- string str, answer;
- while (getline(cin, str)) {
- change_str(str);
- // cout << answer << endl;
- }
- int **new_same_words = new int*[counter];
- for (int i = 0; i < counter; i++) {
- new_same_words[i] = new int[counter];
- for (int j = 0; j < counter; j++)
- new_same_words[i][j] = 0;
- }
- int same_numbers = 0;
- for (int i = 0; i < counter; i++) {
- for (int j = 0; j < 100; j++) {
- for (int h = 0; h < counter; h++) {
- for (int k = 0; k < 100; k++) {
- if ((i != h || j != k) && same_words[i][j] != "" && same_words[h][k] != "") {
- string first_word = same_words[i][j];
- string second_word = same_words[h][k];
- string two_sy_1 = "", two_sy_2 = "";
- int min_length = min(first_word.length(), second_word.length());
- double c = 0;
- for (int g = 0; g < min_length - 1; g++) {
- two_sy_1 += first_word[g];
- two_sy_1 += first_word[g + 1];
- two_sy_2 += second_word[g];
- two_sy_2 += second_word[g + 1];
- // сравнение по 2 символа
- if (two_sy_1 == two_sy_2)
- c++;
- }
- double k = c / (first_word.length() + second_word.length() - c);
- // cout << first_word << " " << second_word << endl << c / (first_word.length() + second_word.length() - c) << endl;
- // cout << i << " " << j << " | " << h << " " << k << endl;
- if (k > 0.45) {
- new_same_words[i][h]++;
- }
- }
- }
- }
- }
- }
- for (int i = 0; i < counter; i++)
- for (int j = i; j < counter; j++) {
- double c2 = new_same_words[i][j];
- // cout << i << " " << j << " " << c2 / (amount_of_words[i] + amount_of_words[j] - c2) << endl;
- double k2 = c2 / (amount_of_words[i] + amount_of_words[j] - c2);
- if (k2 > 0.25) {
- cout << i + 1 << " " << j + 1 << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement