-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapmaker.cpp
75 lines (69 loc) · 2.16 KB
/
mapmaker.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
//#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <iostream>
using namespace std;
int main(){
vector<int> lower(11), upper(11);
vector<vector<int> > c;
int n,r;
//scanf("%d %d", &n, &r);
cin >> n >> r;
string name;
map<string,int> array_lookup;
//array_lookup["jayesh"] = 1;
int base, element_size, d;
for(int i=0;i<n;i++){
//take input information of arrays and compute c values
//scanf("%s %d %d %d", &name, &base, &element_size, &d);
cin >> name >> base >> element_size >> d;
vector<int> temp(d+1);
c.push_back(temp);
for(int j=1;j<=d;j++){
//scanf("%d %d", &lower[j],&upper[j]);
cin >> lower[j] >> upper[j];
}
//compute c values here
c[i][d] = element_size;
int sum = c[i][d] * lower[d];
for(int j = d-1;j >= 1;j--){
c[i][j] = c[i][j+1] * (upper[j+1] - lower[j+1] + 1);
sum += (lower[j] * c[i][j]);
}
c[i][0] = base - sum;
//array_lookup.insert(pair<string,int>(name,i));
array_lookup[name] = i;
//printf("inserting %s %d\n", name,i);
}
map<string,int>:: iterator it;
/*for (it=array_lookup.begin(); it!=array_lookup.end(); ++it){
//printf("map %s %d %d\n",it->first, it->second, array_lookup.size());
cout << "Map" << it->first << " " << it->second << endl;
}*/
//Process the queries using computed c values
string array_name;
for(int i=0;i<r;i++){
//scanf("%s", &array_name);
cin >> array_name;
int array_index = array_lookup[array_name];
//printf("%d %d\n",array_index,array_lookup.size());
int d = c[array_index].size() - 1;
//printf("%d\n",d);
int ans = c[array_index][0];
//printf("%d\n",ans);
int temp;
cout << array_name << "[";
//printf("%s[", array_name);
for(int j=1;j<=d;j++){
//scanf("%d", &temp);
cin >> temp;
ans += (temp*c[array_index][j]);
if(j==1) cout << temp;
else cout << ", " << temp;
}
cout << "] = " << ans << endl;
//printf("] = %d\n", ans);
}
return 0;
}