模拟题。每个单元格有表达式就dfs,如果有环那么就不能解析,可能会重复访问到不能解析的单元格,丢set里或者数组判下重复。

这种题首先框架要对,变量名不要取的太乱,细节比较多,知道的库函数越多越容易写。注意细节,注意格式。

/*********************************************************
* --------------Tyrannosaurus--------- *
* author AbyssalFish *
**********************************************************/
#include<bits/stdc++.h>
using namespace std; typedef long long ll; const int R = , C = , LEN = ; struct Node
{
int n;
string s;
bool tp; //1 num 0 expr
Node(){ s.reserve(LEN); }
}nd[R][C];
int Err[R][C], kas_clk; void readNd(int x,int y)
{
Node &u = nd[x][y];
getline(cin, u.s);
u.tp = !isalpha(u.s[]);// - ,1, A
if(u.tp) {
stringstream ssin(u.s);
ssin>>u.n;
}
} const int ErrorCode = <<; typedef pair<int,int> pii;
vector<pii > un_ev; int vis[R][C], clk;
//parseNd
int dfs(int x,int y)
{
Node &u = nd[x][y];
if(u.tp) return u.n;
if(Err[x][y] == kas_clk) return ErrorCode;
if(vis[x][y] == clk) {
Err[x][y] = kas_clk;
un_ev.push_back(pii(x,y));
return ErrorCode;
}
vis[x][y] = clk;
int ans = , sz = u.s.size();
//stack<char> stk;
for(int i = ; i < sz; i++){
if(isalpha(u.s[i])){
int val = dfs(u.s[i]-'A',u.s[i+]-'');
if(val == ErrorCode) {
if(Err[x][y] != kas_clk){
Err[x][y] = kas_clk;
un_ev.push_back(pii(x,y));
}
return ErrorCode;
}
char op = i?u.s[i-]:'+';//stk.top(); stk.pop();
ans += op=='+'?val:-val;
i++;
}
else if(isdigit(u.s[i])){
int j = i+;
while(j < sz && isdigit(u.s[j])) j++;
int val = atoi(u.s.substr(i,j).c_str());
ans += u.s[i-]=='+'?val:-val;
i = j-;
}
//if(s[i] == '+' || s[i] == '-'){
//}
}
u.tp = true;
return u.n = ans;
} void init()
{
un_ev.reserve(R*C);
} int r,c;
void solve()
{
for(int i = ; i < r; i++){
for(int j = ; j < c; j++){
readNd(i,j);
}
}
kas_clk++;
for(int i = ; i < r; i++)
for(int j = ; j < c; j++){
if(Err[i][j] != kas_clk){
clk++;
dfs(i,j);
}
}
if(un_ev.size()){
sort(un_ev.begin(),un_ev.end());
//un_ev.erase(unique(un_ev.begin(),un_ev.end()),un_ev.end());
for(auto p: un_ev){
int x = p.first, y = p.second;
printf("%c%c: %s\n",x+'A',y+'',nd[x][y].s.c_str());
}
un_ev.clear();
}
else {
putchar(' ');
for(int j = ; j < c; j++) printf("%6d",j);
puts("");
for(int i = ; i < r; i++){
putchar(i+'A');
for(int j = ; j < c; j++){
printf("%6d",nd[i][j].n);
}
puts("");
}
}
puts(""); //注意格式
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
//ios::sync_with_stdio(false);
//cin.tie(nullptr);
init();
while(scanf("%d%d\n",&r,&c),r+c){
solve();
}
return ;
}

UVA 215 Spreadsheet Calculator (模拟)的更多相关文章

  1. Spreadsheet Calculator 电子表格计算器 (Uva 215)

    原题:https://uva.onlinejudge.org/external/2/215.pdf 有一个M x N的表格,每个单元格是个数字或者表达式.表达式由单元格编号和+ - 号组成 输出单元格 ...

  2. 【set&&sstream||floyed判环算法】【UVa 11549】Calculator Conundrum

    CALCULATOR CONUNDRUM Alice got a hold of an old calculator that can display n digits. She was bored ...

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

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

  4. UVA 1156 - Pixel Shuffle(模拟+置换)

    UVA 1156 - Pixel Shuffle 题目链接 题意:依据题目中的变换方式,给定一串变换方式,问须要运行几次才干回复原图像 思路:这题恶心的一比,先模拟求出一次变换后的相应的矩阵,然后对该 ...

  5. UVA 12050 - Palindrome Numbers 模拟

    题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...

  6. Uva 679 Dropping Balls (模拟/二叉树的编号)

    题意:有一颗二叉树,深度为D,所有节点从上到下从左到右编号为1,2,3.....在结点一处放一个小球,每个节点是一个开关,初始全是关闭的,小球从顶点落下,小球每次经过开关就会把它的状态置反,现在问第k ...

  7. ●UVa 1589 Xiangqi(模拟)

    ●赘述题意 给出一个中国象棋残局,告诉各个棋子的位置,黑方只有1枚“将”,红方有至少2枚,至多7枚棋子,包含1枚“帅G”,和若干枚“车R”,“马H”,“炮C”.当前为黑方的回合,问黑方的“将”能否在移 ...

  8. Uva - 512 - Spreadsheet Tracking

    Data in spreadsheets are stored in cells, which are organized in rows (r) and columns (c). Some oper ...

  9. 【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题

    题意:阅读理解难度一道比一道难orz.手摸了好久样例 题解: 读入:大循环用getline读入header顺便处理一下,  里面再写两重循环,外层一次读三个串,内层一次读num个串. 之后就查表,线性 ...

随机推荐

  1. Mysql导入导出数据库11111

    导出: 通过命令行  在MYSQL中的bin文件夹的目录下 输入:D:\phpStudy\MySQL\bin>mysqldump -uroot -p 数据库名 > 导出的文件名 导入: 需 ...

  2. java内存及数据区

    Java运行时的数据区包括:(其中前两个是线程共享的) 1.方法区(Method Area) 存储已被虚拟机加载的类信息.常量.静态变量.即时编译器编译后的代码等数据 2.堆(Heap) 存放对象实例 ...

  3. 水库(树形dp)

    水库 (树形dp) R国有n座城市和n-1条长度为1的双向道路,每条双向道路连接两座城市,城市之间均相互连通.现在你需要维护R国的供水系统.你可以在一些城市修建水库,在第i个城市修建水库需要每年c_i ...

  4. 2017-10-2 清北刷题冲刺班a.m

    一道图论神题 (god) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只 ...

  5. [Xcode 实际操作]四、常用控件-(7)UIStepper控件的使用

    目录:[Swift]Xcode实际操作 本文将演示步进控件的基本用法.步进控件常用于小范围数值的调整. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import ...

  6. javascript基础工具清单

  7. gitlab web端使用

    https://jenkins.io/zh/doc/pipeline/tour/getting-started/ http://www.cnblogs.com/cheng95/p/6542036.ht ...

  8. 关于递归函数返回值为null的问题

    public function gettopcateid($cate_id){ $pid=db('cate')->where('cate_id',$cate_id)->find(); if ...

  9. sql 存储过程-proc

    创建 create proc 存储过程名 (参数列表) as sql 语句 go 执行 exec 存储过程名 参数1,参数2 删除 drop procedure  存储过程名 注: 存储过程名最好以_ ...

  10. input[checkbox],input[radiobox]的一些问题

    复选框和文字对不齐:checkbox复选框的一些深入研究与理解: 解决方案:复选框或单选框与文字对齐的问题的深入研究与一 实例:实例.