UVa 10033 - Interpreter
题目大意:模拟题,有一些寄存器和随机访问内存,给你一些指令以及它们代表的操作,模拟操作即可。
#include <cstdio>
#include <cstring>
#define REGN 10
#define RAMN 1000 int reg[REGN], ram[RAMN]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
//freopen("out", "w", stdout);
#endif
int n;
scanf("%d", &n);
getchar();
char s[];
fgets(s, sizeof(s), stdin);
bool first = true;
while (n--)
{
memset(ram, , sizeof(ram));
int k = ;
while (fgets(s, sizeof(s), stdin))
{
if (s[] == '\n') break;
sscanf(s, "%d", &ram[k]);
k++;
}
int p = ; // p point to the location that will execute
int cnt = ;
memset(reg, , sizeof(reg));
bool end = false;
while (!end)
{
//printf("%d\n", ram[p]);
int hund = ram[p] / ;
int ten = (ram[p] % ) / ;
int unit = ram[p] % ;
cnt++;
switch(hund)
{
case :
if (ram[p] == )
{
end = true;
break;
}
case :
reg[ten] = unit;
p++;
break;
case :
reg[ten] += unit;
reg[ten] %= ;
p++;
break;
case :
reg[ten] *= unit;
reg[ten] %= ;
p++;
break;
case :
reg[ten] = reg[unit];
p++;
break;
case :
reg[ten] += reg[unit];
reg[ten] %= ;
p++;
break;
case :
reg[ten] *= reg[unit];
reg[ten] %= ;
p++;
break;
case :
reg[ten] = ram[reg[unit]];
p++;
break;
case :
ram[reg[unit]] = reg[ten];
p++;
break;
case :
if (reg[unit] != ) p = reg[ten];
else p++;
break;
}
}
if (first) first = false;
else printf("\n");
printf("%d\n", cnt);
}
return ;
}
第一次没在输出之间加一个空行,WA了,又粗心了...同时,又一次疑惑,uva对这种情况是判别为WA而不是PE吗?
UVa 10033 - Interpreter的更多相关文章
- PC/UVa 题号: 110106/10033 Interpreter (解释器)题解 c语言版
, '\n'); #include<cstdio> #include<iostream> #include<string> #include<algorith ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- [工作中的设计模式]解释器模式模式Interpreter
一.模式解析 解释器模式是类的行为模式.给定一个语言之后,解释器模式可以定义出其文法的一种表示,并同时提供一个解释器.客户端可以使用这个解释器来解释这个语言中的句子. 以上是解释器模式的类图,事实上我 ...
- 解释器模式Interpreter详解
原文链接:https://www.cnblogs.com/java-my-life/archive/2012/06/19/2552617.html 在阎宏博士的<JAVA与模式>一书中开头 ...
- Dreamweaver 扩展开发:C-level extensibility and the JavaScript interpreter
The C code in your library must interact with the Dreamweaver JavaScript interpreter at the followin ...
- OpenCASCADE Expression Interpreter by Flex & Bison
OpenCASCADE Expression Interpreter by Flex & Bison eryar@163.com Abstract. OpenCASCADE provide d ...
- PhpStorm和WAMP配置调试参数,问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.
PhpStorm和WAMP配置调试参数 问题描述: Error. Interpreter is not specified or invalid. Press “Fix” to edit your p ...
随机推荐
- opencv mat 转灰度图
Imgproc.cvtColor(sshotmat, sshotmatgray, Imgproc.COLOR_BGR2GRAY); 更多参数看 public class Imgproc { priv ...
- DataBinding注意事项Error parsing XML: duplicate attribute以及如何在listview中使用DataBinding
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- springmvc json数据
的 @RequestMapping("/getAllEdu") @ResponseBody public void getAllEdu(HttpServletRequest req ...
- PHP字节格式化
/** * 容量转换 * @param string $value 字节数值 * @return string */function GBKB($value) { $size = ($value &g ...
- gc CMSMaxAbortablePrecleanTime
https://blogs.oracle.com/jonthecollector/ 链接打不开了,我记得里边说,这个参数是指定vm试图在它指定的时间间隔内等到一次小垃圾回收...minor gc, g ...
- ajax 跨域请求资源问题
其实相当的简单:只需要在服务端设置一下响应头: header("Access-Control-Allow-Origin: *");就可以了!! nice,有木有? 下面两句也可以带 ...
- 【转】Linux 标准目录结构
初学Linux,首先需要弄清Linux 标准目录结构 / root --- 启动Linux时使用的一些核心文件.如操作系统内核.引导程序Grub等. home --- 存储普通用户的个人文件 ftp ...
- ReactiveCocoa Weak-Strong Dance
AC在应用中大量使用了block,由于Objective-C语言的内存管理是基于引用计数的,为了避免循环引用问题,在block中如果要引用self,需要使用@weakify(self)和@strong ...
- bootstrap中可用的图标集
- 图解SQL的各种连接join
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codin ...