forked from harshithatlb/programming_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reviews.cpp
113 lines (95 loc) · 2.88 KB
/
reviews.cpp
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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <string>
#include <map>
using namespace std;
int withinTime(time_t uts){
tm *ts;
ts = gmtime (&uts);
if ( ts->tm_year+1900 != 2016 )
return 10;
if (ts->tm_mon+1 == 6 && ts->tm_mday >15)
return 20;
if (ts->tm_mon+1 == 7 && ts->tm_mday <15 )
return 20;
if ((ts->tm_mon+1) <6 || (ts->tm_mon+1) >7)
return 10;
return 10;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
// n : number of passions
// m : no of reviews
int n,m;
cin>> n >> m;
vector<string> passions(100);
for (int i = 0;i< n;i++){
cin >> passions[i];
transform(passions[i].begin(), passions[i].end(), passions[i].begin(), ::tolower);
}
map<string, int > pointsMap;
map<string, int>::iterator it;
string review;
int id;
int points;
time_t uts;
string findstr;
for (int i = 0; i<m; i++ ){
cin >> id;
cin >> uts;
points = withinTime(uts);
cin.ignore();
getline (cin , review, '\n');
if (review.length() >= 100 )
points+=20;
else if (review.length()>0 && review.length() <100 )
points+=10;
transform(review.begin(), review.end(), review.begin(), ::tolower);
//finding the passion in the text;
for (int j = 0; j < n;j++){
if ( review.find(passions[j])!=string::npos){
findstr = to_string(id)+ ","+ to_string(j); //reviewerID+ passion
it = pointsMap.find (findstr);
if (it!= pointsMap.end())
points+=it->second;
pointsMap.insert (make_pair(findstr,points));
}
}
}
it = pointsMap.begin();
int pointsArr[n];
int revId[n];
for (int i = 0; i<n; i++){
revId[i] = -1;
pointsArr[i] = -1;
}
map<int, int>::iterator maxIt;
// finding highest reviewer
for (it = pointsMap.begin(); it!=pointsMap.end();it++){
string f = it->first;
string r = it->first;
std::string::size_type sz;
int pos = f.find(',');
f = f.substr(pos+1, f.length());
r = r.substr (0, pos);
string topicStr;
int reviewerId = stoi (r, nullptr, 10);
int topic = stoi(f, nullptr,10);
if (pointsArr[topic] < it->second){
pointsArr[topic] =it->second;
revId[topic] = reviewerId;
}else if (pointsArr[topic] == it->second){
// points are equal, check id, take the smallest Id
if ( revId[topic] > reviewerId )
revId[topic] = reviewerId;
}
}
for (int i = 0; i<n; i++){
cout <<revId[i] << "\n";
}
return 0;
}