题目

题目

 


 

分析

算是个模拟吧

 


 

代码

#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(模拟)的更多相关文章

  1. UVA 1596 Bug Hunt (大模拟 栈)

    题意: 输入并模拟执行一段程序,输出第一个bug所在的行. 每行程序有两种可能: 数组定义: 格式为arr[size]. 例如a[10]或者b[5],可用下标分别是0-9和0-4.定义之后所有元素均为 ...

  2. UVa 1596 Bug Hunt (string::find && map && 模拟)

    题意 : 给出几组由数组定义与赋值构成的编程语句, 有可能有两种BUG, 第一种为数组下标越界, 第二种为使用尚未定义的数组元素, 叫你找出最早出现BUG的一行并输出, 每组以' . '号分隔, 当有 ...

  3. 【技巧性(+递归运用)】UVa 1596 - Bug Hunt

    In this problem, we consider a simple programming language that has only declarations of onedimensio ...

  4. uva 1596 Bug Hunt

    In this problem, we consider a simple programming language that has only declarations of one-dimensi ...

  5. UVa 1596 Bug Hunt (STL栈)

    题意:给定两种操作,一种是定义一个数组,另一种是赋值,让你找出哪一步时出错了,出错只有两种,一种是数组越界,另一种是访问未定义变量. 析:当初看到这个题时,感觉好麻烦啊,然后就放过去了,而现在要重新回 ...

  6. [刷题]算法竞赛入门经典(第2版) 5-9/UVa1596 - Bug Hunt

    //开学了,好烦啊啊啊啊啊!怎么开个学那么多破事情!!都俩星期了,终于有时间写出来一道题 题意:不难理解,不写了.这几天忙的心累. 代码:(Accepted, 0.010s) //UVa1596 - ...

  7. 【习题 5-9 UVA - 1596】Bug Hunt

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] map模拟 map<string,int>记录每个数组的大小 map <pair<string, int&g ...

  8. Bug Hunt UVA - 1596

      In this problem, we consider a simple programming language that has only declarations of onedimens ...

  9. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

随机推荐

  1. 如何使用JFinal开发javaweb

    介绍开始: 编辑器:MyEclipse; 数据库:MySQL; 服务器:tomcat; 1 首先新建web项目 要强调的是Target runtime必须选择为None.然后点击两次Next,选中创建 ...

  2. [AirFlow]AirFlow使用指南四 DAG Operator Task

    1. DAG 在Airflow中,DAG或有向无环图是你运行所有任务的集合,以某种组织方式来反映所有任务之间的关系和依赖. 例如,一个简单的DAG可以包括三个任务:A,B和C.可以说A必须在B运行之前 ...

  3. 修改程序版本工具(ResHacker)使用说明20140902

    有时候我们需要自己修改dll版本号,那么ResHacker工具可以帮我们在不需要开发帮助下可以自己修改版本号: 工具:直接复制出来即可 1.双击打开工具 2.将dll文件或者exe文件拖拽进来,或者[ ...

  4. boost split字符串

    boost split string , which is very convenience #include <string> #include <iostream> #in ...

  5. 【测试工具】tcpdump + wireshark 抓包实践

    Tcpdump + Wireshark 抓包实践 工具介绍 Tcpdump 看到dump大家应该有所意识吧,就是下载数据,抓数据.tcpdump是linux下的一个抓取tcp包的命令 Usage: t ...

  6. BZOJ1412 ZJOI2009 狼和羊的故事 【网络流-最小割】

    BZOJ1412 ZJOI2009 狼和羊的故事 Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和 ...

  7. Java8新特性——StreamAPI(一)

    1. 流的基本概念 1.1 什么是流? 流是Java8引入的全新概念,它用来处理集合中的数据,暂且可以把它理解为一种高级集合. 众所周知,集合操作非常麻烦,若要对集合进行筛选.投影,需要写大量的代码, ...

  8. How to install cacti on centos 6

    Cacti – Network and performance monitoring tool   Cacti is one of best monitoring tool used to monit ...

  9. Mybatis新增返回主键的两种方法 (mysql)

    1.自增:LAST_INSERT_ID (自动返回最后一个INSERT或 UPDATE 问询为 AUTO_INCREMENT列设置的第一个 发生的值.) <!-- mysql的自增ID :LAS ...

  10. centos 限制只能访问某个目录的php文件

    vi /etc/php.ini #编辑 open_basedir = .:/tmp/ #在380行 设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果 ...