-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
120 lines (110 loc) · 2.56 KB
/
main.cpp
File metadata and controls
120 lines (110 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <fstream>
#include <map>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <boost\regex.hpp>
boost::regex PUNCTSIGN("[^à-ÿ]");
boost::regex E("(¸|¨)");
using namespace std;
string tolow(string s) //function translate word to lower case
{
const int temp='à'-'À';
for(int i=0; i<s.length(); ++i)
{
if((s[i]>='À') && (s[i]<='ß')) s[i]+=temp;
}
return s;
}
string normalization(string s)
{
s=tolow(s);
s=regex_replace(s,E,"e");
s=regex_replace(s,PUNCTSIGN,"");
return s;
}
void input(map<string,int> &words, string &name) //input text with add to map of words
{
ifstream in;
string s;
cin>>name;
in.open(name);
while(in>>s)
{
s=normalization(s);
if(s.length()<7) continue;
if (words.count(s)>0)
words[s]++;
else
words.insert(pair<string,int>(s,1));
}
in.close();
}
void weighting(map<string,int> &file1,vector<int> &weight,string name)
{
ifstream in;
string s;
in.open(name);
int currectWieght=0;
while(in>>s)
{
if(s.length()<7) continue;
if(s[s.length()-1]=='.' || s[s.length()-1]=='?' || s[s.length()-1]=='!')
{
s=normalization(s);
currectWieght+=file1[s];
weight.push_back(currectWieght);
currectWieght==0;
}
s=normalization(s);
currectWieght+=file1[s];
}
}
void output(vector<int> weight, string name)
{
vector<int> number;
for(int i=0;i<5;++i)
{
auto it=max_element(begin(weight),end(weight));
number.push_back(it-weight.begin());
weight.erase(it);
}
ifstream in;
string s;
in.open(name);
int num=0;
while(in>>s)
{
if(s[s.length()-1]=='.' || s[s.length()-1]=='?' || s[s.length()-1]=='!')
{
if(find(number.begin(), number.end(), num) != number.end())
{
cout<<s<<endl;
}
num++;
continue;
}
if(find(number.begin(), number.end(), num) != number.end())
{
cout<<s<<" ";
}
}
}
int main()
{
setlocale(LC_ALL, "rus");
map<string,int> mapFile1;
vector<int> weight;
string name;
cout<<"Please, enter first file name"<<endl;
input(mapFile1,name);
weighting(mapFile1,weight,name);
output(weight,name);
map <string,int>::iterator cur;
for (cur=mapFile1.begin();cur!=mapFile1.end();cur++)
{
cout<<(*cur).first<<": "<<(*cur).second<<endl;
}
return 0;
}