UVALive 7324 ASCII Addition (模拟)
ASCII Addition
题目链接:
http://acm.hust.edu.cn/vjudge/contest/127407#problem/A
Description
Nowadays, there are smartphone applications that instantly translate text and even solve math problems
if you just point your phone’s camera at them. Your job is to implement a much simpler functionality
reminiscent of the past — add two integers written down as ASCII art.
An ASCII art is a matrix of characters, exactly 7 rows high, with each individual character either
a dot (.) or the lowercase letter ‘x’.
An expression of the form a+b is given, where both a and b are positive integers. The expression is
converted into ASCII art by writing all the expression characters (the digits of a and b as well as the ‘+’
sign) as 7 × 5 matrices, and concatenating the matrices together with a single column of dot characters
between consecutive individual matrices. The exact matrices corresponding to the digits and the ‘+’
sign are as folows:
```
xxxxx ....x xxxxx xxxxx x...x xxxxx xxxxx xxxxx xxxxx xxxxx .....
x...x ....x ....x ....x x...x x.... x.... ....x x...x x...x ..x..
x...x ....x ....x ....x x...x x.... x.... ....x x...x x...x ..x..
x...x ....x xxxxx xxxxx xxxxx xxxxx xxxxx ....x xxxxx xxxxx xxxxx
x...x ....x x.... ....x ....x ....x x...x ....x x...x ....x ..x..
x...x ....x x.... ....x ....x ....x x...x ....x x...x ....x ..x..
xxxxx ....x xxxxx xxxxx ....x xxxxx xxxxx ....x xxxxx xxxxx .....
```
Given an ASCII art for an expression of the form a + b, find the result of the addition and write it
out in the ASCII art form.
Input
The input file contains several test cases, each of them as described below.
Input consists of exactly 7 lines and contains the ASCII art for an expression of the form a + b,
where both a and b are positive integers consisting of at most 9 decimal digits and written without
leading zeros.
Output
For each test case, output 7 lines containing ASCII art corresponding to the result of the addition,
without leading zeros.
Sample Input
```
....x.xxxxx.xxxxx.x...x.xxxxx.xxxxx.xxxxx.......xxxxx.xxxxx.xxxxx
....x.....x.....x.x...x.x.....x.........x...x...x...x.x...x.x...x
....x.....x.....x.x...x.x.....x.........x...x...x...x.x...x.x...x
....x.xxxxx.xxxxx.xxxxx.xxxxx.xxxxx.....x.xxxxx.xxxxx.xxxxx.x...x
....x.x.........x.....x.....x.x...x.....x...x...x...x.....x.x...x
....x.x.........x.....x.....x.x...x.....x...x...x...x.....x.x...x
....x.xxxxx.xxxxx.....x.xxxxx.xxxxx.....x.......xxxxx.xxxxx.xxxxx
```
Sample Output
```
....x.xxxxx.xxxxx.xxxxx.x...x.xxxxx.xxxxx
....x.....x.....x.x.....x...x.x.........x
....x.....x.....x.x.....x...x.x.........x
....x.xxxxx.xxxxx.xxxxx.xxxxx.xxxxx.....x
....x.x.........x.....x.....x.....x.....x
....x.x.........x.....x.....x.....x.....x
....x.xxxxx.xxxxx.xxxxx.....x.xxxxx.....x
```
##题意:
用题所示的格式输入 A + B 的式子,要以相同格式输出结果.
##题解:
对每个数字存一下,把输入串分割成若干个数字(或'+'),然后暴力判读入的每个数即可.
注意string没有赋初值时候不能直接对某个位置赋值,直接用重定义过的'+'连接字符即可.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 1010
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
string num[11][7] = {
{"xxxxx",
"x...x",
"x...x",
"x...x",
"x...x",
"x...x",
"xxxxx"}
,
{"....x",
"....x",
"....x",
"....x",
"....x",
"....x",
"....x",}
,
{"xxxxx",
"....x",
"....x",
"xxxxx",
"x....",
"x....",
"xxxxx"}
,
{"xxxxx",
"....x",
"....x",
"xxxxx",
"....x",
"....x",
"xxxxx"}
,
{"x...x",
"x...x",
"x...x",
"xxxxx",
"....x",
"....x",
"....x"}
,
{"xxxxx",
"x....",
"x....",
"xxxxx",
"....x",
"....x",
"xxxxx"}
,
{"xxxxx",
"x....",
"x....",
"xxxxx",
"x...x",
"x...x",
"xxxxx"}
,
{"xxxxx",
"....x",
"....x",
"....x",
"....x",
"....x",
"....x",}
,
{"xxxxx",
"x...x",
"x...x",
"xxxxx",
"x...x",
"x...x",
"xxxxx"}
,
{"xxxxx",
"x...x",
"x...x",
"xxxxx",
"....x",
"....x",
"xxxxx"}
,
{".....",
"..x..",
"..x..",
"xxxxx",
"..x..",
"..x..",
"....."}
};
int match(string cur[]) {
for(int i=0; i<10; i++) {
int flag = 1;
for(int j=0; j<7; j++) {
for(int k=0; k<5; k++)
if(num[i][j][k] != cur[j][k]) {
flag = 0; break;
}
}
if(flag) return i;
}
return -1;
}
string data[10];
string print[10];
int main(int argc, char const *argv[])
{
//IN;
while(cin >> data[0])
{
for(int i=1; i<7; i++)
cin >> data[i];
int len = data[0].size();
int n = (len + 1) / 6;
LL a=0,b=0; int flag = 0;
int start = 0;
string cur[10];
for(int i=1; i<=n; i++) {
for(int j=0; j<7; j++) {
cur[j].clear();
for(int k=start; k<start+5; k++) {
cur[j] += data[j][k];
}
}
int dig = match(cur);
if(dig == -1) {
flag = 1;
start += 6;
continue;
}
if(!flag) {
a = a*10LL + dig;
} else {
b = b*10LL + dig;
}
start += 6;
}
LL Ans = a + b;
vector<int> ans; ans.clear();
while(Ans) {
int di = Ans % 10LL;
Ans /= 10LL;
ans.push_back(di);
}
int sz = ans.size();
for(int i=0; i<10; i++) print[i].clear();
for(int i=sz-1; i>=0; i--) {
for(int j=0; j<7; j++) {
for(int k=0; k<5; k++) {
print[j] += num[ans[i]][j][k];
}
if(i) print[j] += '.';
}
}
for(int i=0; i<7; i++) {
cout << print[i] << endl;
}
}
return 0;
}
UVALive 7324 ASCII Addition (模拟)的更多相关文章
- UVALive 7464 Robots(模拟)
7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...
- UVALive - 6269 Digital Clock 模拟
UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...
- UVALive - 7139(差分+模拟)
题目链接 参考 题意 N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 分析 由于车的起点和终点都为左上角,且每个格子里的人永远面对着车, ...
- 【Bit String Reordering UVALive - 6832 】【模拟】
题意分析 题目讲的主要是给你一个01串,然后给你要变成的01串格式,问你要转换成这一格式最少需要移动的步数. 题目不难,但当时并没有AC,3个小时的个人赛1道没AC,归根到底是没有逼自己去想,又想的太 ...
- 【Miscalculation UVALive - 6833 】【模拟】
题目分析 题目讲的是给你一个串,里面是加法.乘法混合运算(个人赛中误看成是加减乘除混合运算),有两种算法,一种是乘法优先运算,另一种是依次从左向右运算(不管它是否乘在前还是加在前). 个人赛中试着模拟 ...
- UVaLive 6809 Spokes Wheel (模拟)
题意:给定两个16进制数,问你把它转成二进制后,把第一个向左或者向右旋转最少的次数同,使得第一个变成第二个. 析:也是比较水的,按照要求做就好,注意0的情况,可能会忘记. #pragma commen ...
- [洛谷P4346][CERC2015]ASCII Addition
题目大意:给一个像素的$a+b$,每个数字为$7\times5$的像素,每两个数字之间有间隔 题解:乱搞读入 卡点:无 C++ Code: #include <cstdio> #inclu ...
- UVALive 6858 Frame (模拟)
Frame 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/D Description http://7xjob4.com1.z0 ...
- gym101480
A. ASCII Addition 模拟 #include <iostream> #include <sstream> #include <algorithm> # ...
随机推荐
- [转载]深入理解JAVA的接口和抽象类
深入理解Java的接口和抽象类 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太多不同的地方.很多人在初学的 ...
- Apple开发者账号申请学习方式
http://jingyan.baidu.com/article/414eccf610e7c76b431f0a94.html https://developer.apple.com/wwdc/sche ...
- RecyclerView(5)官方教程带简单示例
Create Lists The RecyclerView widget is a more advanced and flexible version of ListView. This widge ...
- LRU缓存算法
http://blog.csdn.net/beiyeqingteng/article/details/7010411 http://blog.csdn.net/wzy_1988/article/det ...
- csv 文件介绍
CSV即Comma Separate Values,这种文件格式经常用来作为不同程序之间的数据交互的格式. 具体文件格式 每条记录占一行 以逗号为分隔符 逗号前后的空格会被忽略 字段中包含有逗号,该字 ...
- 关于Hibernate中的Configuration
Hibernate中,关于从 Configuration中建立一个SessionFactory常用的可以有两种方法,一种是为Configuration提供hibernate.cfg.xml配置文件,还 ...
- 二维树状数组(水题) POJ1195
前段时间遇到线段树过不了,树状数组却过了的题.(其实线段树过得了的) 回忆了下树状数组. 主要原理,还是二进制位数,每一项的和表示其为它的前((最后一位1及其后)的二进制数)和,可从二进制图来看.(用 ...
- bzoj4080
分组赛时wy大神讲的题,网上都是随机化的题解 我来讲一下正解吧,我们穷举两个点,这两点距离要小于限制 然后我们分别以这两个点为圆心,两点距离为半径画圆 圆圆相交的部分被两点练成线段划分成两部分,不难发 ...
- Qt之进程间通信(QProcess)
简述 QProcess可以在应用程序内部与其它进程通信,或启动其它应用程序.与在终端机之类的命令输入窗口上使用名称和参数是一样的,可以使用QProcess提供的函数start()启动进程.可以注册QS ...
- HDU 3492 (直线与所有线段相交) Segment
题意: 给出n个线段,判断是否存在一条直线使得所有线段在直线上的射影的交非空. 分析: 如果我们找到一条与所有线段相交的直线,然后做一条与该直线垂直的直线,这些线段在直线上的射影就一定包含这个垂足. ...