这两个题,讲的是有一种奇怪的语言,代码是一种二维的矩阵。

前一个题,是根据所给的要求,写一个简单的解释器。

后一个题,是用那种语言写一个简单的小程序。

挺有意思的,所以在这里纪念一下。顺便那个语言的原型是一种叫做Befunge的语言。真实存在的哟。

代码:

  简单的解释器:  

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <cctype>
#include <time.h> using namespace std; const int INF = <<;
const int MAXN = ;
const int MAXM = 1e5+;
const int MAXSTEP = 1e6;
const int MAX_NUM = 1e5;
const int dir[][] = { {, }, {, }, {, -}, {-, } }; int H, W;
char G[MAXN][MAXN];
int num[MAXM], n, curNum;
int pointer[], d;
int stepCnt; int cur, memory[]; bool check() {
if (!(-MAX_NUM<=cur&&cur<=MAX_NUM)) {
//溢出错误
puts("OVERFLOW ERROR");
return false;
}
stepCnt++;
if (stepCnt>=MAXSTEP) {
//超时
puts("TIME LIMIT EXCEEDED");
return false;
}
pointer[] += dir[d][]; pointer[] += dir[d][];
if (!(<=pointer[]&&pointer[]<H && <=pointer[]&&pointer[]<W)) {
//指针越界
puts("RUNTIME ERROR");
return false;
}
if (curNum>=n) curNum = n-;
return true;
} void init() {
//初始化寄存器
cur = ;
memset(memory, , sizeof(memory));
//初始化指针
pointer[] = pointer[] = ;
d = ;
//初始化计数器
stepCnt = ;
curNum = ;
} void run() {
init();
while (true) {
char c = G[pointer[]][pointer[]];
if ('#'==c)
break;
else if ('^'==c)
d = ;
else if ('v'==c)
d = ;
else if ('<'==c)
d = ;
else if ('>'==c)
d = ;
else if ('@'==c)
if (cur!=) d = (d+)%;
else d = (d+)%;
else if ('A'<=c&&c<='Z')
swap(cur, memory[c-'A']);
else if ('?'==c) {
cur = num[curNum++];
} else if ('!'==c) {
printf("%d\n", cur);
cur = ;
} else if ('+'==c)
cur++;
else if ('-'==c)
cur--;
else if ('.'==c)
;
if (!check()) break;
}
} int main() {
#ifdef Phantom01
freopen("URAL2027.txt", "r", stdin);
#endif //Phantom01 while (scanf("%d%d", &H, &W)!=EOF) {
for (int i = ; i < H; i++)
scanf("%s", G[i]);
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &num[i]);
run();
} return ;
}

解释器

  小程序:

 9 12
?..........v
>.>v>>Tv>>v.
.>.>@..>@^I.
.-..I..^A.-.
.^..+..^+.v<
.T..I..-A...
.^+T<..^<...
^.........@v
........#!A<

小程序

URAL 2027 2028 两个有趣的题的更多相关文章

  1. Ural 1209. 1, 10, 100, 1000... 一道有趣的题

    1209. 1, 10, 100, 1000... Time limit: 1.0 secondMemory limit: 64 MB Let's consider an infinite seque ...

  2. URAL - 1917 Titan Ruins: Deadly Accuracy(水题)

    水题一个,代码挫了一下: 题意不好理解. 你去一个洞窟内探险,洞窟内有许多宝石,但都有魔法守护,你需要用魔法将它们打下来. 每个宝石都有自己的防御等级,当你的魔法超过它的防御等级时它就会被你打下来. ...

  3. 两道相似KMP题

    1.POJ 3450 Coporate Identity 这两题的解法都是枚举子串,然后匹配,像这种题目以后可以不用KMP来做,直接字符串自带的strstr函数搞定,如果字符串未出现,该函数返回NUL ...

  4. URAL 1008 - Image Encoding(bfs坑爹题)

    坑爹题,两种输入输出互相交换,裸bfs #include <stdio.h> #include <string.h> typedef struct { int x; int y ...

  5. 又一道简单题&&Ladygod(两道思维水题)

    Ladygod Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  6. 一道cf水题再加两道紫薯题的感悟

    . 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...

  7. bzoj1814 Ural 1519 Formula 1(插头dp模板题)

    1814: Ural 1519 Formula 1 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 924  Solved: 351[Submit][Sta ...

  8. FJOI2020 的两道组合计数题

    最近细品了 FJOI2020 的两道计数题,感觉抛开数据范围不清还卡常不谈里面的组合计数技巧还是挺不错的.由于这两道题都基于卡特兰数的拓展,所以我们把它们一并研究掉. 首先是 D1T3 ,先给出简要题 ...

  9. 发现两个有趣的CSS3效果

    一.CSS3画机器猫 http://keleyi.com/keleyi/phtml/html5/3.htm 哆啦A梦效果图: 可用于浏览器对CSS3支持情况的测试 但最近有人对这个测试表示怀疑,指该测 ...

随机推荐

  1. AIM Tech Round 5 1028cf(A-E)

    AIM Tech Round 5 (codeforces上题目编号是1028)(A-E) ---完全被这次比赛打击,自己真的很渣--- 战况 依旧3题选手 被构造题坑得好惨 稍稍涨了rating,希望 ...

  2. C语言基本语法——函数

    1.什么是函数 2.函数语法 3.函数声明 4.函数调用 5.函数的形参与实参 6.return与exit关键字 7.递归函数 1.什么是函数 • 函数就是一连串语句被组合在一起,并指定了一个名字 • ...

  3. BZOJ 2631 [国家集训队]Tree II (LCT)

    题目大意:给你一棵树,让你维护一个数据结构,支持 边的断,连 树链上所有点点权加上某个值 树链上所有点点权乘上某个值 求树链所有点点权和 (辣鸡bzoj又是土豪题,洛谷P1501传送门) LCT裸题, ...

  4. linux系统添加环境变量,node.js forever 守护进程添加环境变量

    1.node.js 守护进程组件 forever 安装 npm install forever -g 安装完成后截图: 2.安装完成后在控制台输入 forever 出现 -bash: forever: ...

  5. JS中常用开发知识点

     JS中常用开发知识点 1.获取指定范围内的随机数 2.随机获取数组中的元素 3.生成从0到指定值的数字数组 等同于: 4.打乱数字数组的顺序 5.对象转换为数组 //注意对象必须是以下格式的才可以通 ...

  6. 2015 Multi-University Training Contest 7 hdu 5373 The shortest problem

    The shortest problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. 基于nginx的静态网页部署

    背景: 一序列的html网页需要部署 基于nginx的部署: 本文采用的基于openresty的nginx 配置. 简单地配置 Nginx 的配置文件,以便在启动 Nginx 时去启用这些配置即可实现 ...

  8. ACdream 1127(Base Station-树状数组-2个约束条件)

    Base Station Time Limit: 20000/10000MS (Java/Others)Memory Limit: 512000/256000KB (Java/Others) Subm ...

  9. Genymotion出现Installation error: INSTALL_FAILED_CPU_ABI_INCOMPATIBLE错误解决方法

    今天在Genymotion上执行曾经的一个项目(libs中有多个SDK和so文件)时,出现下面错误: Console控制台中:Installation error: INSTALL_FAILED_CP ...

  10. TYVJ1415 差分约束

    思路: i–>i+1连一条边权为0的边 i–>i-1连一条边权为-1的边 start-1 ->end 连一条边权为w的边 求0->n的最长路即可 //By SiriusRen ...