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
| #include <cstdio> #include <unordered_map> #include <string> using std::string;
int main() { struct data { int base, size, D; int L[10], R[10];
int C[10];
data() {} data(int _base, int _size, int _D) : base(_base), size(_size), D(_D) { for (int i = 0; i < D; ++i) scanf("%d%d", &L[i], &R[i]);
C[D - 1] = size; for (int i = D - 2; i >= 0; --i) C[i] = C[i + 1] * (R[i + 1] - L[i + 1] + 1); } };
std::unordered_map<string, data> M;
int N, R; char name[15]; scanf("%d%d", &N, &R); for (int i = 0; i < N; ++i) { int base, size, d; getchar(); scanf("%s%d%d%d", name, &base, &size, &d); M[string(name)] = (data){base, size, d}; }
for (int i = 0; i < R; ++i) { getchar(); scanf("%s", name); printf("%s[", name); data &d = M[string(name)];
int addr = d.base, tmp; for (int i = 0; i < d.D; ++i) { scanf("%d", &tmp); addr += (tmp - d.L[i]) * d.C[i];
if (i) printf(", %d", tmp); else printf("%d", tmp); }
printf("] = %d\n", addr); }
return 0; }
|