【UVA】1596 Bug Hunt(模拟)
题目
分析
算是个模拟吧
 
代码
#include <bits/stdc++.h>
using namespace std;
map<int,int> a[130];
char s[85];
int n[130];
int PosIs()
{
	int len=strlen(s);
	for(int i=0;i<len;i++)
		if(s[i]=='=') return i;
	return -1;
}
int get_num(int k)
{
	int res=0;
	if(isalpha(s[k]))
	{
		int t=get_num(k+2);
		if(t<0|| t>=n[s[k]] || !a[s[k]].count(t))
			res=-1;
		else res=a[s[k]][t];
	}
	for(int i=k;isdigit(s[i]);i++)
	{
		if(i==k && s[i]=='0' && isalpha(s[i+1]))
		{
			res=-1;
			break;
		}
		res=res*10+s[i]-'0';
	}
	return res;
}
int main()
{
	int res=0;
	while(scanf("%s",s) && s[0]!='.')
	{
		int ans=0,cnt=0;
		for(int i=0;i<130;i++) a[i].clear();
		do
		{
			if(ans) continue;
			cnt++;
			int k=PosIs();
			if(k<0)
			{
				int t=get_num(2);
				if(t<0){ans=cnt; continue;}
				n[s[0]]=t;
			}
			else
			{
				int t1=get_num(2);
				if(t1<0||t1>=n[s[0]]) {ans=cnt;continue;}
				int t2=get_num(k+1);
				if(t2<0) {ans=cnt;continue;}
				a[s[0]][t1]=t2;
			}
		}while(scanf("%s",s) && s[0]!='.');
		printf("%d\n",ans);
	}
	return 0;
}
【UVA】1596 Bug Hunt(模拟)的更多相关文章
- UVA 1596 Bug Hunt (大模拟 栈)
		题意: 输入并模拟执行一段程序,输出第一个bug所在的行. 每行程序有两种可能: 数组定义: 格式为arr[size]. 例如a[10]或者b[5],可用下标分别是0-9和0-4.定义之后所有元素均为 ... 
- UVa 1596 Bug Hunt (string::find && map && 模拟)
		题意 : 给出几组由数组定义与赋值构成的编程语句, 有可能有两种BUG, 第一种为数组下标越界, 第二种为使用尚未定义的数组元素, 叫你找出最早出现BUG的一行并输出, 每组以' . '号分隔, 当有 ... 
- 【技巧性(+递归运用)】UVa 1596 - Bug Hunt
		In this problem, we consider a simple programming language that has only declarations of onedimensio ... 
- uva 1596 Bug Hunt
		In this problem, we consider a simple programming language that has only declarations of one-dimensi ... 
- UVa 1596 Bug Hunt (STL栈)
		题意:给定两种操作,一种是定义一个数组,另一种是赋值,让你找出哪一步时出错了,出错只有两种,一种是数组越界,另一种是访问未定义变量. 析:当初看到这个题时,感觉好麻烦啊,然后就放过去了,而现在要重新回 ... 
- [刷题]算法竞赛入门经典(第2版) 5-9/UVa1596 - Bug Hunt
		//开学了,好烦啊啊啊啊啊!怎么开个学那么多破事情!!都俩星期了,终于有时间写出来一道题 题意:不难理解,不写了.这几天忙的心累. 代码:(Accepted, 0.010s) //UVa1596 - ... 
- 【习题 5-9 UVA - 1596】Bug Hunt
		[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] map模拟 map<string,int>记录每个数组的大小 map <pair<string, int&g ... 
- Bug Hunt UVA - 1596
		In this problem, we consider a simple programming language that has only declarations of onedimens ... 
- UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0
		题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ... 
随机推荐
- PostgreSQL copy命令使用记录
			上篇写到用pg_bulkload来导入数据,但是实际的环境是solaris,pg_bulkload还不支持,于是用copy的方式,下面附上脚本 -bash-4.1$ cat copy.sh #!/bi ... 
- 【跟着stackoverflow学Pandas】How to iterate over rows in a DataFrame in Pandas-DataFrame按行迭代
			最近做一个系列博客,跟着stackoverflow学Pandas. 以 pandas作为关键词,在stackoverflow中进行搜索,随后安照 votes 数目进行排序: https://stack ... 
- Hibernate Validator参数校验
			日常开发中经常会遇到需要参数校验的情况,比如某个字段不能为空.长度不能超过5等都属于参数校验的范围.对于简单的参数校验通过写几个if-else判断语句就搞定,但是对于复杂的多个参数校验的情况,就不是那 ... 
- redis事务浅析
			事务可以简单理解为:把多件事当做一件事情处理,要么一起成功,要么一起失败.在Spring中可以配置一个事务管理器,然后在要进行事务处理的方法上添加@Transactional注解就可以了. 对于red ... 
- Swift UITextField各种属性的设置
			//MARK: 文本输入框 func _initTextField() { //如果需要在模拟器中调用电脑的键盘 快捷键:command + shift + k let textField = UIT ... 
- stack组件03
			继昨天留下的问题 思路: 结果: 优化: from stark.service.site import site,ModelSatrk from .models import * from djang ... 
- I.MX6 Linux eGTouch TouchScreen porting
			I.MX6 Linux eGTouch TouchScreen porting 一.Download Driver: http://www.eeti.com.tw/drivers_Linux.html ... 
- LARAVEL IOC容器 示例解析
			<?php class People { public $dog = null; public function __construct() { $this->dog = new Dog( ... 
- HDU3652 B-number 数位DP第二题
			A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ... 
- 20179223《Linux内核原理与分析》第十二周学习笔记
			Return-to-libc 攻击实验 一.实验描述 缓冲区溢出的常用攻击方法是用 shellcode 的地址来覆盖漏洞程序的返回地址,使得漏洞程序去执行存放在栈中 shellcode.为了阻止这种类 ... 
