【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 ...
随机推荐
- Java虚拟机读写其他进程的数据--Process对象
使用Runtime对象的exec()方法可以运行平台上的其他程序,该方法产生一个Process对象,Process对象代表由该Java程序启动的子进程. Process类提供了3个方法,用于让程序和其 ...
- vue.js 源代码学习笔记 ----- 工具方法 error
import config from '../config' import { warn } from './debug' import { inBrowser } from './env' // 这 ...
- 配置mysql 允许远程连接
今天折腾了好常时间远程连接mysql ,在云服务器里面打开了3306端口,使用了service mysql status查看到mysql进程正常. netstat -anp | grep mysql ...
- 【OpenCV入门教程之二】 一览众山小:OpenCV 2.4.8 or OpenCV 2.4.9组件结构全解析
本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/19925819 作者:毛星云 ...
- vueRouter中scrollBehavior实现滚动固定位置
使用前端路由,当切换到新路由时,想要页面滚到顶部,或者是保持原先的滚动位置,就像重新加载页面那样. vue-router 能做到,而且更好,它让你可以自定义路由切换时页面如何滚动. 注意: 这个功能只 ...
- 【转】react-native开发混合App-github开源项目
http://www.lcode.org/study-react-native-opensource-one/ http://gold.xitu.io/entry/575f498c128fe10057 ...
- [置顶]
滴滴插件化VirtualAPK框架原理解析(二)之Service 管理
在前一篇博客滴滴插件化框架VirtualAPK原理解析(一)之插件Activity管理 中VirtualAPK是如何对Activity进行管理的,本篇博客,我们继续来学习这个框架,这次我们学习的是如何 ...
- Android中开发需要的高效助推的命令总结
Android 开发中我们有时候需要借助一些命令帮助更好的高效率定位解决问题,本文就来介绍一些可能有些隐藏的而却非常好用的命令,可以帮我们快速找到问题,这些命令都是本人在开发中实践总结,个人觉得非常 ...
- python中封装
封装 引子 从封装的本身意思去理解,封装就是用一个袋子,把买的水果.书.水杯一起装进袋子里,然后再把袋子的口给封上,照这样的理解来说,封装=隐藏,但是,这种理解是片面的 ## 如何封装 在python ...
- Python的安装与设置
1.Python的下载与安装最新的python 版本下载可以去python的网站进行下载 . 考虑系统兼任这里下载32位的Python 双击下载的exe文件进行安装 单击Next 完成Python 安 ...