A certain computer has 10 registers and 1000 words of RAM. Each register or RAM location holds a 3-digit integer between 0 and 999. Instructions are encoded as 3-digit integers and stored in RAM. The encodings are as follows:

• 100 means halt

• 2dn means set register d to n (between 0 and 9)

• 3dn means add n to register d

• 4dn means multiply register d by n

• 5ds means set register d to the value of register s

• 6ds means add the value of register s to register d

• 7ds means multiply register d by the value of register s

• 8da means set register d to the value in RAM whose address is in register a

• 9sa means set the value in RAM whose address is in register a to the value of register s

• 0ds means goto the location in register d unless register s contains 0

All registers initially contain 000. The initial content of the RAM is read from standard input. Thefirst instruction to be executed is at RAM address 0. All results are reduced modulo 1000.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The input to your program consists of up to 1000 3-digit unsigned integers, representing the contents of consecutive RAM locations starting at 0. Unspecified RAM locations are initialized to 000.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

The output from your program is a single integer: the number of instructions executed up to and including the halt instruction. You may assume that the program does halt.

Sample Input

1

299

492

495

399

492

495

399

283

279

689

078

100

000

000

000

Sample Output

16

问题链接UVA10033 Interpreter

问题简述:(略)

问题分析

这是一个模拟题,模拟指令的执行过程,内容包括指令、寄存器和存储器。

程序说明

需要注意输入格式的处理。

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* UVA10033 Interpreter */#include <bits/stdc++.h>using namespace std;const int N1 = 1000;
const int N2 = 10;
int ram[N1], reg[N2];int main()
{int t;cin >> t;cin.get();cin.get();while(t--) {memset(reg, 0, sizeof reg);memset(ram, 0, sizeof ram);int add = 0, ans;string inst;while(getline(cin, inst)) {if(inst.empty())break;for(auto c : inst)ram[add] = ram[add] * 10 + c - '0';add++;}ans = add = 0;while(true) {ans++;int cmd = ram[add++];if(cmd == 100)break;int op = cmd / 100, operand1 = cmd % 100 / 10, operand2 = cmd % 10;switch(op) {case 0:if(reg[operand2]) add = reg[operand1];break;case 2:reg[operand1] = operand2;break;case 3:(reg[operand1] += operand2) %= 1000;break;case 4:(reg[operand1] *= operand2) %= 1000;break;case 5:reg[operand1] = reg[operand2];break;case 6:(reg[operand1] += reg[operand2]) %= 1000;break;case 7:(reg[operand1] *= reg[operand2]) %= 1000;break;case 8:reg[operand1] = ram[reg[operand2]];break;case 9:ram[reg[operand2]] = reg[operand1];break;}}cout << ans << '\n';if(t)cout << '\n';}return 0;
}

UVA10033 Interpreter【模拟】相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. ICPC程序设计题解书籍系列之八:(美)斯基纳等:《挑战编程-程序设计竞赛训练手册》

    S书<挑战编程--程序设计竞赛训练手册>题目一览 1 Getting Started UVA100 POJ1207 HDU1032 The 3n + 1 problem[水题] - 海岛B ...

  3. qemu模拟执行固件文件(解决 Invalid ELF image for this architecture 问题)

    kali下qemu的安装: apt-get install qemu 使用Docker容器进行操作 https://hub.docker.com/r/asmimproved/qemu-mips/ 分析 ...

  4. 【Python】模拟面试技术面试题答

    一. python语法 1. 请说一下你对迭代器和生成器的区别? 2. 什么是线程安全? 3. 你所遵循的代码规范是什么?请举例说明其要求? 4. Python中怎么简单的实现列表去重? 5. pyt ...

  5. Python模拟智能开关设备MQTT接入阿里云物联网平台 - PyCharm paho.mqtt

    概要 Python 使用 paho.mqtt 库,利用阿里云物联网平台的设备证书:productKey.deviceName.deviceSecret,自动合成 userName.passWord.以 ...

  6. 【白话设计模式二十二】解释器模式(Interpreter)

    为什么80%的码农都做不了架构师?>>>    #0 系列目录# 白话设计模式 工厂模式 单例模式 [白话设计模式一]简单工厂模式(Simple Factory) [白话设计模式二] ...

  7. Java 模拟面试题

    1.面向对象的特点 继承,封装,多态 2.对象和类的区别是什么? 对象是对客观事物的抽象,类是对对象的抽象.类是一种抽象的数据类型,它们的关系是,对象是类的实例,类是对象的模板. 3.静态成员和实例成 ...

  8. 1.6.6 解释器 Interpreter

    PC/UVA 110106/10033 本题..模拟即可. //author: CHC //First Edit Time: 2014-01-12 22:00 //Last Edit Time: 20 ...

  9. python实现音乐定时开关,模拟上下课铃声(含程序打包微小exe文件方法介绍)

    本文分两部分,先介绍python实现模拟上下课定时铃声播放与关闭,再讲python程序打包成小型exe文件. 一.python实现模拟上下课定时铃声播放与关闭 不说废话,完整代码奉上. import ...

最新文章

  1. 秒啊!程序员防猝死指南来了!
  2. thinkphp-查询数据-基本查询
  3. 各纬度气候分布图_读我国一月平均气温分布图,寻找我国冬季气温最高和最低的地方...
  4. Android 使用Adapter适配器模式实现无线轮播BannerView
  5. CORS 跨域-哪些操作不受同源限制
  6. 局部描述符表LDT的作用+定义+初始化+跳转相关
  7. WinAPI-CreateMutex(双开)
  8. python自带的PIL库扩展图片大小给图片加上文字描述
  9. Linux使用SSH上传下载文件,linux下用ssh上传,下载文件
  10. Git安装配置与GitHub注册及简单使用
  11. python 字符串处理_python 数据清洗之字符串处理
  12. 关于HTTPOXY漏洞的分析说明
  13. 理解 CMOS IMAGE Sensor
  14. 【iOS】使用 otool 命令查看 App 所使用的动态库
  15. Bloombox:iPhone陶瓷底座,还能当花盆和扩音器
  16. 基于routeros的ADSL带宽叠加
  17. C++STL常用算法adjacent_find
  18. 【LeetCode - 马化腾】第一次看到马总的代码
  19. 4.3 jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company**
  20. linux面试题_全网最新、最全Linux面试题(2020版)!

热门文章

  1. GDAL的一个BUG
  2. 前端JAVASCRIPT模块化开发
  3. 几种ELK常见的架构模式
  4. webgame 上线版本控制
  5. c++ arm 图像处理_方案解析丨如何在ARM平台搭建超声波无损探伤系统
  6. 中转换成list集合_Java集合、数组与泛型中的几个陷阱,你掉进了几个?
  7. Linux编译LLVM,如何使用ninja快速编译LLVM和Clang(以llvm3.3为例子)
  8. vue查询列表中所有用户信息_vue实现全匹配搜索列表内容
  9. 剑指offer面试题25. 合并两个排序的链表(双指针)
  10. tensorflow精进之路(二十六)——人脸识别(上)(MTCNN原理)