-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanipulation.cpp
132 lines (106 loc) · 3.43 KB
/
manipulation.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// manipulation.cpp
// Source File (C++14)
// AUTHOR: JISHAN SHAIKH ([email protected])
// GitHuB: github.com/jishanshaikh4/ LinkedIn: linkedin.com/in/jishanshaikh
// SUBMITTED TO: Store Transaction Imputation (Hackathon organized by Nielson (India) Pvt. Ltd.)
// COMPILE IT AS: g++ manipulation.cpp -o manipulation
// EXECUTE IT AS: ./manipulation
// Now, You will ask why C++, and why not Python3, it is the language of data science?
// Because of fast processing of data at runtime FOR THIS TASK. And, choice of language depends on each task.
// We have to get our work done, no matter what the language is. And, don't think that I don't know Python.'
/*
INPUT FILE: values.txt
- Processed sorted data values for MONTH, STORE, and GROUP (Total 26985 values)
- For sorting and consistency purposes, N10 is renamed as N9a.
OUTPUT: output.txt
- Total values
*/
#include <bits/stdc++.h>
using namespace std;
// A very efficient string matching algorithm implementation in O(string_size)
bool mmmatch(string a, string b){
if(a.size() != b.size())
return false;
for(int i=0; i<a.size(); i++)
if(a[i] != b[i])
return false;
return true;
}
// Driver code for testing and execution
int main(){
freopen("values.txt", "r", stdin);
freopen("outputt.txt", "w", stdout);
// Data holders
double value[26985];
string month[26985];
string store[26985];
// group array is an array of unique group items
// And out of 26985, there are only 81 unique groups :)
string group[81];
// Instead of storing all the text info of groups, we store group_array uniquely, and matched them as group_ids
// Basically idea of hashing from group_strings to group_strings_unique as per ids, which are stored below
int group_ids[26985];
int results[3][10][81];
// Taking input from stdin, values.txt
for(int i=0; i<81; i++){
string s;
getline(cin, s);
group[i] = s;
}
for(int i=0; i<26985; i++){
value[i] = 0.0;
}
for(int i=0; i<26985; i++){
cin >> value[i];
}
for(int i=0; i<26985; i++){
cin >> month[i];
}
for(int i=0; i<26985; i++){
cin >> store[i];
}
for(int i=0; i<26985; i++){
string x;
getline(cin, x);
for(int j=0; j<81; j++){
if(mmmatch(x, group[j])){
group_ids[i] = j;
}
}
}
// Descriptors for month_index, store_index, and group_index
int mi = 0, si = 0, gi = 0;
//for(int i=0; i<26985; i++)
// cout << month[i] << " " << store[i] << " " << value[i] << " " << group_ids[i] << endl;
// STORING ALL VALUES IN SORTED ORDER (STORE, MONTH, GROUP)
for(int i=0; i<26985; i++){
if(month[i] == "M1") mi = 0;
else if(month[i] == "M2") mi = 1;
else if(month[i] == "M3") mi = 2;
if(store[i] == "N1") si = 0;
else if(store[i] == "N2") si = 1;
else if(store[i] == "N3") si = 2;
else if(store[i] == "N4") si = 3;
else if(store[i] == "N5") si = 4;
else if(store[i] == "N6") si = 5;
else if(store[i] == "N7") si = 6;
else if(store[i] == "N8") si = 7;
else if(store[i] == "N9") si = 8;
else if(store[i] == "N9a") si = 9;
results[mi][si][group_ids[i]] += value[i];
// Checking out manually for a few values
//cout << mi << "\t" << si << "\t" << value[i] << "\t" << group_ids[i] << endl;
}
// IDs starting for mi = 0, si = 0, and group_index = 0
long long fid = 1112535LL;
cout << "ID" << "\t" << "VALUE" << endl;
for(int i=0; i<3; i++){
for(int j=0; j<10; j++){
for(int k=0; k<81; k++){
cout << fid << "\t" << results[i][j][k] << endl;
fid += 4;
}
}
}
return 0;
}