Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7.  
  8. struct str {
  9. string s;
  10. vector <string> words;
  11. int num_of_words;
  12. };
  13.  
  14.  
  15. vector <str> writings;
  16. vector <char> stroke;
  17. vector <char> new_stroke;
  18.  
  19.  
  20.  
  21. string normalize(string s, int num);
  22.  
  23.  
  24.  
  25. int main() {
  26. freopen("input.txt", "r", stdin);
  27. freopen("output.txt", "w", stdout);
  28.  
  29. string temp;
  30.  
  31.  
  32. for (size_t i = 0; getline(cin, temp); ++i) {
  33.  
  34. if (temp.size() != 0) {
  35. writings.resize(i + 1);
  36. temp = normalize(temp, i);
  37. writings[i].s = temp;
  38. }
  39.  
  40. else
  41. --i;
  42. }
  43.  
  44. double same = 0;
  45.  
  46.  
  47. for (size_t i = 0; i < writings.size(); ++i)
  48. for (size_t j = i; j < writings.size(); ++j) {
  49.  
  50. if (i == j)
  51. continue;
  52.  
  53. for (size_t words_1 = 0; words_1 < writings[i].num_of_words; ++words_1) {
  54. for (size_t words_2 = 0; words_2 < writings[j].num_of_words; ++words_2) {
  55. int min_len;
  56.  
  57. min_len = min(writings[i].words[words_1].length(), writings[j].words[words_2].length());
  58.  
  59. double c = 0;
  60.  
  61. for (size_t k = 0; k < min_len; ++k)
  62. if (writings[i].words[words_1][k] == writings[j].words[words_2][k])
  63. ++c;
  64.  
  65. double a = writings[i].words[words_1].length();
  66. double b = writings[j].words[words_2].length();
  67. double l = c / (a + b - c);
  68.  
  69. if (l > 0.45)
  70. ++same;
  71. }
  72. }
  73.  
  74. double len_1 = writings[i].num_of_words;
  75. double len_2 = writings[j].num_of_words;
  76. double last_k = same / (len_1 + len_2 - same);
  77.  
  78. if (last_k > 0.25)
  79. printf("%d %d\n", i + 1, j + 1);
  80.  
  81. same = 0;
  82. }
  83.  
  84. }
  85.  
  86.  
  87.  
  88. string normalize(string s, int num) {
  89.  
  90. for (size_t i = 0; i < s.size(); ++i) {
  91. if (s[i] >= '0' && s[i] <= '9')
  92. stroke.push_back(s[i]);
  93.  
  94. else if (s[i] >= 'a' && s[i] <= 'z')
  95. stroke.push_back(s[i]);
  96.  
  97. else if (s[i] >= 'A' && s[i] <= 'Z')
  98. stroke.push_back(s[i] + 32);
  99.  
  100. else if (s[i] == ' ')
  101. stroke.push_back(s[i]);
  102. }
  103.  
  104.  
  105. stroke.push_back('*');
  106.  
  107. bool backspace = true;
  108. int counter = 0;
  109. string word = "";
  110. writings[num].num_of_words = 0;
  111.  
  112. for (size_t i = 0; i < stroke.size() - 1; ++i) {
  113.  
  114. if (stroke[i] == ' ') {
  115. if (backspace == false && i != 0) {
  116.  
  117. new_stroke.push_back(stroke[i]);
  118. backspace = true;
  119.  
  120. }
  121. }
  122.  
  123. else {
  124. for (size_t j = i; stroke[j] != ' ' && j < stroke.size() - 1; ++j)
  125. counter++;
  126.  
  127. if (counter > 3) {
  128. size_t j;
  129.  
  130. for (j = i; stroke[j] != ' ' && j < stroke.size() - 1; ++j) {
  131. word += stroke[j];
  132. new_stroke.push_back(stroke[j]);
  133. }
  134.  
  135.  
  136. writings[num].words.resize(writings[num].num_of_words + 1);
  137. writings[num].words[writings[num].num_of_words] = word;
  138. ++writings[num].num_of_words;
  139. word = "";
  140.  
  141. backspace = false;
  142. }
  143.  
  144.  
  145. i += counter - 1;
  146. counter = 0;
  147. }
  148. }
  149.  
  150. string temp = "";
  151.  
  152. for (size_t i = 0; i < new_stroke.size(); ++i)
  153. temp += new_stroke[i];
  154.  
  155. stroke.clear();
  156. new_stroke.clear();
  157.  
  158. return temp;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement