Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. struct Plag_check {
  8. string s;
  9. string word[1000];
  10. int k = 0;
  11. };
  12.  
  13. Plag_check str[1000];
  14.  
  15. void String_normalization(int i)
  16. {
  17. string ans = str[i].s;
  18. for (int i = 0; i < ans.length(); i++)
  19. {
  20. if (ans[i] >= '0' && ans[i] <= '9')
  21. continue;
  22. if (ans[i] >= 'a' && ans[i] <= 'z')
  23. continue;
  24. if (ans[i] == ' ')
  25. continue;
  26. if (ans[i] >= 'A' && ans[i] <= 'Z')
  27. {
  28. ans[i] += 32;
  29. continue;
  30. }
  31.  
  32. ans.erase(i, 1);
  33. i--;
  34. }
  35.  
  36. for (int i = 0, k = 0; i < ans.length(); i++)
  37. {
  38. if ((ans[i] >= 'a' && ans[i] <= 'z') || (ans[i] >= '0' && ans[i] <= '9'))
  39. k++;
  40. else
  41. {
  42. if (i == 0 || ans[i - 1] == ' ')
  43. {
  44. ans.erase(i, 1);
  45. i--;
  46. }
  47. else if (k > 0 && k <= 3)
  48. {
  49. ans.erase(i - k, k + 1);
  50. i -= k + 1;
  51. }
  52. k = 0;
  53. }
  54.  
  55. if (i == ans.length() - 1 && ans[i] != ' ')
  56. {
  57. if (k > 0 && k <= 3)
  58. {
  59. ans.erase(i - k + 1, k);
  60. }
  61. }
  62. }
  63. str[i].s = ans;
  64. }
  65.  
  66.  
  67. float cword(int i, int j)
  68. {
  69. float c = 0;
  70. float g = 0;
  71. for (int k = 0; k < str[i].word[k].length(); k++)
  72. {
  73. for (int l = 0; l < str[j].word[l].length(); l++)
  74. {
  75. for (int m = 0; m < str[i].word[k].length() && m < str[j].word[l].length(); m++)
  76. if (str[i].word[k][m] == str[j].word[l][m])
  77. c++;
  78. if (c / (str[i].word[k].length() + str[j].word[l].length() - c) > 0.45)
  79. g++;
  80. c = 0;
  81. }
  82. }
  83. return g;
  84. }
  85.  
  86.  
  87. void cstr(int i, int j)
  88. {
  89. float c_word = cword(i, j);
  90. if (c_word / (str[i].k + str[j].k - c_word) > 0.25)
  91. {
  92. cout << "";
  93. cout << i + 1 << " " << j + 1 << endl;
  94. }
  95. }
  96.  
  97.  
  98. int main()
  99. {
  100. freopen("input.txt", "r", stdin);
  101. freopen("output.txt", "w", stdout);
  102. ios_base::sync_with_stdio(0);
  103. cin.tie(0);
  104. string s;
  105. int n = 0;
  106. int c = 0;
  107.  
  108. while (getline(cin, s))
  109. {
  110. str[n].s = s;
  111. n++;
  112. }
  113.  
  114. for (int i = 0; i < n; i++)
  115. {
  116. String_normalization(i);
  117. }
  118.  
  119. for (int i = 0; i < n; i++)
  120. {
  121. c = 0;
  122. for (int j = 0; j < str[i].s.length(); j++)
  123. {
  124. while (str[i].s[j] != ' ' && j<str[i].s.length())
  125. {
  126. str[i].word[c] = str[i].word[c] + str[i].s[j];
  127. j++;
  128. }
  129. c++;
  130. str[i].k++;
  131. }
  132. }
  133.  
  134.  
  135. for (int i = 0; i < n - 1; i++)
  136. {
  137. for (int j = i + 1; j < n; j++)
  138. {
  139. cstr(i, j);
  140. }
  141. }
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement