Advertisement
myLoveOnlyForYou

Untitled

Mar 3rd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. string answers[1000];
  8. string same_words[100][100];
  9. int counter = 0;
  10. int amount_of_words[100];
  11.  
  12. void change_str(string str) {
  13.     string answer = "";
  14.     int word_length = 0;
  15.     for (char& a : str) {
  16.         if ((a >= 'a' && a <= 'z') || (a == ' ') || (a >= 'A' && a <= 'Z') || (a >= '0' && a <= '9')) {
  17.             if (a != ' ')
  18.                 word_length++;
  19.             if (a >= 'A' && a <= 'Z') {
  20.                 char ch((int)a + 32);
  21.                 answer += ch;
  22.             }
  23.             else
  24.                 answer += a;
  25.         }
  26.         if (a == ' ') {
  27.             // cout << answer << " " << word_length << endl;
  28.             if (word_length <= 3) {
  29.                 for (int j = 0; j <= word_length; j++)
  30.                     answer.pop_back();
  31.             }
  32.             word_length = 0;
  33.         }
  34.     }
  35.     // это нормализация
  36.     answers[counter] = answer;
  37.     int word_counter = 0;
  38.     string word = "";
  39.     for (char&a : answer) {
  40.         if (a != ' ')
  41.             word += a;
  42.         else if (a == ' ') {
  43.             same_words[counter][word_counter] = word;
  44.             word = "";
  45.             word_counter++;
  46.         }
  47.         // здесь двумерный массив из слов создается
  48.     }
  49.     same_words[counter][word_counter] = word;
  50.     amount_of_words[counter] = word_counter;
  51.     counter++;
  52. }
  53.  
  54. int main() {
  55.     freopen("input.txt", "r", stdin);
  56.     freopen("output.txt", "w", stdout);
  57.     char a;
  58.     string str, answer;
  59.     while (getline(cin, str)) {
  60.         change_str(str);
  61.         // cout << answer << endl;
  62.     }
  63.     int **new_same_words = new int*[counter];
  64.     for (int i = 0; i < counter; i++) {
  65.         new_same_words[i] = new int[counter];
  66.         for (int j = 0; j < counter; j++)
  67.             new_same_words[i][j] = 0;
  68.     }
  69.     int same_numbers = 0;
  70.     for (int i = 0; i < counter; i++) {
  71.         for (int j = 0; j < 100; j++) {
  72.             for (int h = 0; h < counter; h++) {
  73.                 for (int k = 0; k < 100; k++) {
  74.                     if ((i != h || j != k) && same_words[i][j] != "" && same_words[h][k] != "") {
  75.                         string first_word = same_words[i][j];
  76.                         string second_word = same_words[h][k];
  77.                         string two_sy_1 = "", two_sy_2 = "";
  78.                         int min_length = min(first_word.length(), second_word.length());
  79.                         double c = 0;
  80.                         for (int g = 0; g < min_length - 1; g++) {
  81.                             two_sy_1 += first_word[g];
  82.                             two_sy_1 += first_word[g + 1];
  83.  
  84.                             two_sy_2 += second_word[g];
  85.                             two_sy_2 += second_word[g + 1];
  86.                             // сравнение по 2 символа
  87.                             if (two_sy_1 == two_sy_2)
  88.                                 c++;
  89.                         }
  90.  
  91.                         double k = c / (first_word.length() + second_word.length() - c);
  92.                         // cout << first_word << " " << second_word << endl << c / (first_word.length() + second_word.length() - c) << endl;
  93.                         // cout << i << " " << j << " | " << h << " " << k << endl;
  94.                         if (k > 0.45) {
  95.                             new_same_words[i][h]++;
  96.                         }
  97.                     }
  98.                 }
  99.             }
  100.         }
  101.     }
  102.  
  103.  
  104.     for (int i = 0; i < counter; i++)
  105.         for (int j = i; j < counter; j++) {
  106.             double c2 = new_same_words[i][j];
  107.             // cout << i << " " << j << " " << c2 / (amount_of_words[i] + amount_of_words[j] - c2) << endl;
  108.             double k2 = c2 / (amount_of_words[i] + amount_of_words[j] - c2);
  109.             if (k2 > 0.25) {
  110.                 cout << i + 1 << " " << j + 1 << endl;
  111.             }
  112.         }
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement