【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 ...
随机推荐
- ImportError: liblapack.so.3: cannot open shared object file问题
问题: 安装完tensorflow后,在终端输入: python import cv2 出现如下错误: ImportError: liblapack.so.3: cannot open shared ...
- Okhttp之RealConnection建立链接简单分析
在之前的博客中我们知道Okhttp在发起链接请求先从链接池中获取连接,如果链接池中没有链接则创建新的链接RealConnection对象,然后执行其connet方法打开SOCKET链接(详见< ...
- Mac OS 升级到10.12问题 Android ADT 下载SDK问题 https://dl-ssl.google.com refused...
缘由: 更新sdk,遇到了更新下载失败问题: Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml Fetch ...
- Familia:百度NLP开源的中文主题模型应用工具包
参考:Familia的Github项目地址.百度NLP专栏介绍 Familia 开源项目包含文档主题推断工具.语义匹配计算工具以及基于工业级语料训练的三种主题模型:Latent Dirichlet A ...
- 常见Git操作及关键知识点
一.Git三区概念 工作区 (work dict) 暂存区(stage)(add 是添加到当前的暂存区) 提交区(就是当前工作的分支master分支或者branches分支) git 所有操作都是基于 ...
- Python3 字符串操作
截掉指定字符串 # 截掉指定字符串 string.strip("what you want to delete") #截掉字符串左边的空格 string.lstrip() #截掉字 ...
- 在IIS上搭建FTP站点
操作环境 系统:win7 IIS版本:7.5 FTP传输工具:FlashXP 概述 本文介绍了如何在win7下利用IIS(默认已安装IIS和FTP功能)搭建FTP站点,FTP站点的常用配置. 快速搭建 ...
- baos bais 意义
import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOut ...
- IOS在Document目录下创建文件夹、保存、读取、以及删除文件
// 在Documents目录下创建一个名为LaunchImage的文件夹 NSString *path = [[NSHomeDirectory() stringByAppendingPathComp ...
- linux自学(九)之开始centos学习,安装数据库MariaDB
上一篇:linux自学(八)之开始centos学习,安装tomcat 数据库我们不安装mysql,我网上看了好多资料发现mysql安装比较麻烦,我们这里安装同一个父亲的产品MariaDB.驱动,端口等 ...