编程介的小学生 2017-09-07 15:02 采纳率: 20.5%
浏览 779
已采纳

Mapmaker

The Cybersoft Computer Company (a leader in programming languages) has hired you to work on a new programming language named A--. Your task is to work on the array mapping tasks of the language. You will take an array reference such as x[5,6] and map it to an actual physical address. In preparation for doing this, you will write a program that will read in several array declarations and references and give the physical address of each reference. The physical address output by the program should be an integer number in base 10.
The physical address of an array reference A[i1 , i2 , . . ., iD ] is calculated from the formula C0 + C1i1 + C2i2 + . . . + CDiD, where the constants C0 . . . CD are calculated as specified below.

B = Base address of the array
D = Number of dimensions in the array
Ld = Lower bound of dimension d
Ud = Upper bound of dimension d
CD = Array element size in bytes
Cd = Cd+1 (Ud+1 - Ld+1 + 1) for 1 <= d < D
C0 = B - C1L1 - C2L2 - . . . - CDLD

Input

The first line of the input file contains two positive integers. The first integer specifies N, the number of arrays defined in the data file, and the second integer specifies R, the number of array references for which addresses should be calculated. The next N lines each define an array, one per line, and the following R lines contain one array reference per line for which an address should be calculated.

Each line which defines an array contains, in the following order, the name of the array (which is limited to 10 characters), a positive integer which specifies the base address of the array, a positive integer which specifies the size in bytes of each array element, and D, the number of dimensions in the array (no array will have fewer than 1 or more than 10 dimensions). This is followed on the same line by D pairs of integers which represent the lower and upper bounds, respectively, of dimensions 1 . . . D of the array.

Each line which specifies an array reference contains the name of the array followed by the integer indexes i1, i2, . . ., iD where D is the dimension of the array.

Output

The output file should contain the array references and the physical addresses. There should be one array reference and physical address per line. The formatting guidelines below must be adhered to.

For each line of output:

  1. Output the name of the array

  2. Output a left square bracket

  3. Output each index value (each pair of indexes should have a single comma and space between them)

  4. Output a right square bracket, a space, an equal sign, and another space

  5. Output the physical address

Sample Input

3 4
ONE 1500 2 2 0 3 1 5
TWO 2000 4 3 1 4 0 5 5 10
THREE 3000 1 1 1 9
ONE 2 4
THREE 7
TWO 2 0 6
TWO 3 3 9

Sample Output

ONE[2, 4] = 1526
THREE[7] = 3006
TWO[2, 0, 6] = 2148
TWO[3, 3, 9] = 2376

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-23 00:57
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?