Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 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("count_big.txt"); //C:\Users\wasya\CLionProjects\servak
  23. string word;
  24. int rate;
  25. map<string, pair<set<string>, int>> count_big;
  26. string wordInc;
  27. while (file >> word && file >> rate){
  28. set<string> set;
  29. if (word.size() == 1) {
  30. set.insert(word);
  31. auto para1 = make_pair(set, rate);
  32. auto para = make_pair(word, para1);
  33. count_big.insert(para);
  34. continue;
  35. } else {
  36. for (int i = 0; i < word.size() - 1; i++) {
  37. set.insert(word.substr(i, 2));
  38. }
  39. }
  40. auto para1 = make_pair(set, rate);
  41. auto para = make_pair(word, para1);
  42. count_big.insert(para);
  43. }
  44.  
  45. while (cin >> wordInc){
  46. set<string> set;
  47. if (wordInc.size() == 1){
  48. set.insert(wordInc);
  49. } else {
  50. for (int i = 0; i < wordInc.size() - 1; i++){
  51. set.insert(wordInc.substr(i, 2));
  52. }
  53. }
  54. double koef = 0;
  55. string output;
  56. int rate = 0;
  57. for (auto pair : count_big){
  58. double measure = meas_simm(set, pair.second.first);
  59. if (measure > koef){
  60. koef = measure;
  61. output = pair.first;
  62. rate = pair.second.second;
  63. } else if (measure == koef){
  64. if (rate < pair.second.second){
  65. koef = measure;
  66. output = pair.first;
  67. rate = pair.second.second;
  68. } else if (rate == pair.second.second){
  69. if (pair.first < output){
  70. koef = measure;
  71. output = pair.first;
  72. rate = pair.second.second;
  73. }
  74. }
  75. }
  76. }
  77. cout << output << endl;
  78. }
  79. file.close();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement