Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. #include <set>
  7. #include <algorithm>
  8.  
  9. using namespace std;
  10.  
  11. double meas_simm(set<string> set1, set<string> set2){
  12. set<string> s3;
  13. set<string> s4;
  14. set_intersection(set1.begin(), set1.end(), set2.begin(), set2.end(), inserter(s3, s3.begin()));
  15. set_union(set1.begin(), set1.end(), set2.begin(), set2.end(), inserter(s4, s4.begin()));
  16. return (double)s3.size() / (double) s4.size();
  17. }
  18.  
  19.  
  20.  
  21. int main(){
  22. ifstream file("C:\\Users\\wasya\\CLionProjects\\servak\\count_big.txt"); //C:\Users\wasya\CLionProjects\servak
  23. string word;
  24. int rate;
  25. // double koef = 0;
  26. // string output;
  27. // int curRate = 0;
  28. // map<string, pair<set<string>, int>> count_big;
  29. string wordInc;
  30. vector<set<string>> bigSet;
  31. array<string, 20> ans;
  32. array<int, 20> vecRate;
  33. array<double, 20> vecKoef;
  34. ans.fill("zz");
  35. vecRate.fill(0);
  36. vecKoef.fill(0);
  37. for (int i = 0 ; i < 10; i++){
  38. cin >> wordInc;
  39. // while (cin >> wordInc){
  40. set<string> curSet;
  41. for (int i = 0; i < wordInc.size(); i++){
  42. curSet.insert(wordInc.substr(i, 2));
  43. }
  44. bigSet.push_back(curSet);
  45. }
  46.  
  47.  
  48. while (file >> word && file >> rate){
  49. set<string> curSet;
  50. if (word.size() == 1){
  51. curSet.insert(word);
  52. } else {
  53. for (int i = 0; i < word.size() - 1; i++) {
  54. curSet.insert(word.substr(i, 2));
  55. }
  56. }
  57. for (int i = 0; i < bigSet.size(); i++) {
  58. double measure = meas_simm(bigSet[i], curSet);
  59.  
  60. if (measure > vecKoef[i]){
  61. vecKoef[i] = measure;
  62. ans[i] = word;
  63. vecRate[i] = rate;
  64. } else if (measure == vecKoef[i]){
  65. if (rate > vecRate[i]){
  66. vecKoef[i] = measure;
  67. ans[i] = word;
  68. vecRate[i] = rate;
  69. } else if (rate == vecRate[i]){
  70. if (word < ans[i]){
  71. vecKoef[i] = measure;
  72. ans[i] = word;
  73. vecRate[i] = rate;
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80. for (int i = 0; i < ans.size(); i++){
  81. if (ans[i] == "zz") break;
  82. cout << ans[i] << endl;
  83. }
  84.  
  85. // while (file >> word && file >> rate){
  86. // set<string> set;
  87. // if (word.size() == 1) {
  88. // set.insert(word);
  89. // } else {
  90. // for (int i = 0; i < word.size() - 1; i++) {
  91. // set.insert(word.substr(i, 2));
  92. // }
  93. // }
  94. // auto para = make_pair(word, make_pair(set, rate));
  95. // count_big.insert(para);
  96. // }
  97. //
  98. // while (cin >> wordInc){
  99. // set<string> set;
  100. // if (wordInc.size() == 1){
  101. // set.insert(wordInc);
  102. // } else {
  103. // for (int i = 0; i < wordInc.size() - 1; i++){
  104. // set.insert(wordInc.substr(i, 2));
  105. // }
  106. // }
  107. // double koef = 0;
  108. // string output;
  109. // int rate = 0;
  110. // for (auto pair : count_big){
  111. // double measure = meas_simm(set, pair.second.first);
  112. // if (measure > koef){
  113. // koef = measure;
  114. // output = pair.first;
  115. // rate = pair.second.second;
  116. // } else if (measure == koef){
  117. // if (rate < pair.second.second){
  118. // koef = measure;
  119. // output = pair.first;
  120. // rate = pair.second.second;
  121. // } else if (rate == pair.second.second){
  122. // if (pair.first < output){
  123. // koef = measure;
  124. // output = pair.first;
  125. // rate = pair.second.second;
  126. // }
  127. // }
  128. // }
  129. // }
  130. // cout << output << endl;
  131. // }
  132. file.close();
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement