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 ...
随机推荐
- php socket客户端及服务器端应用实例
经常有朋友会对php的socket应用充满疑惑,本文就以实例代码作一讲解,希望能对初学php的朋友起到一点帮助作用 具体代码如下: 1.服务器端代码: <?php class SocketSer ...
- 理解free命令
free的输出: total used free shared buffers cached Mem: -/+ buffers/cache: Swap: 第一行: total:总内存 used:已使用 ...
- Python之路【第二篇】:Python基础(二)
windows的换行符:\n\r linux的换行符:\n 文件的数据处理: r 以只读模式打开文件(默认模式)w 以只写模式打开文件a 以追加模式打开文件 r+b 以读写模式打开文件(以读/写方式打 ...
- laravel提示Mcrypt PHP extension required
系统Ubuntu 安装Apache,php后发现laravel报 Mcrypt PHP extension required错误 解决办法: apt-get install php5-mcrypt c ...
- iis7支持asp(访问页面,页面存在仍然提示404)
1. win7下安装IIS时ASP一般被默认不选中的状态,因此需要打开IIS检查功能视图栏中是否存在ASP选项,若没有则需要从控制面板->程序和 功能->打开或关闭Windows功能-&g ...
- Sonya and Problem Wihtout a Legend
Sonya and Problem Wihtout a Legend Sonya was unable to think of a story for this problem, so here co ...
- pop动画使用示例
// 弹簧动画 POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame]; an ...
- (转)MultipleOutputFormat和MultipleOutputs
MultipleOutputFormat和MultipleOutputs http://www.cnblogs.com/liangzh/archive/2012/05/22/2512264.html ...
- 转:总结Selenium WebDriver中一些鼠标和键盘事件的使用
在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...
- Chapter 1 First Sight——7
Eventually we made it to Charlie's. 最终我们到了查理斯的家. He still lived in the small,two-bedroom house that ...