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

  1. UVALive 7464 Robots(模拟)

    7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...

  2. UVALive - 6269 Digital Clock 模拟

    UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...

  3. UVALive - 7139(差分+模拟)

    题目链接 参考 题意 N*M的网格,一辆车沿着网格线按给定路线走,每个网格里有一个人,人的视线始终看着车,问这些人净转圈数的平方和. 分析 由于车的起点和终点都为左上角,且每个格子里的人永远面对着车, ...

  4. 【Bit String Reordering UVALive - 6832 】【模拟】

    题意分析 题目讲的主要是给你一个01串,然后给你要变成的01串格式,问你要转换成这一格式最少需要移动的步数. 题目不难,但当时并没有AC,3个小时的个人赛1道没AC,归根到底是没有逼自己去想,又想的太 ...

  5. 【Miscalculation UVALive - 6833 】【模拟】

    题目分析 题目讲的是给你一个串,里面是加法.乘法混合运算(个人赛中误看成是加减乘除混合运算),有两种算法,一种是乘法优先运算,另一种是依次从左向右运算(不管它是否乘在前还是加在前). 个人赛中试着模拟 ...

  6. UVaLive 6809 Spokes Wheel (模拟)

    题意:给定两个16进制数,问你把它转成二进制后,把第一个向左或者向右旋转最少的次数同,使得第一个变成第二个. 析:也是比较水的,按照要求做就好,注意0的情况,可能会忘记. #pragma commen ...

  7. [洛谷P4346][CERC2015]ASCII Addition

    题目大意:给一个像素的$a+b$,每个数字为$7\times5$的像素,每两个数字之间有间隔 题解:乱搞读入 卡点:无 C++ Code: #include <cstdio> #inclu ...

  8. UVALive 6858 Frame (模拟)

    Frame 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/D Description http://7xjob4.com1.z0 ...

  9. gym101480

    A. ASCII Addition 模拟 #include <iostream> #include <sstream> #include <algorithm> # ...

随机推荐

  1. flume介绍以及环境的部署

    收集.聚合时间流数据分布式框架.通常用户log数据 采用ad-hoc方案,明显有点如下: 可靠的.可伸缩.可管理.可定制.高性能 声名式配置,可以动态配置 提供上下文路由功能 支持负载均衡和故障转移 ...

  2. 函数fil_node_create

    /*******************************************************************//** Appends a new file to the c ...

  3. struct TABLE

    struct TABLE { TABLE() {} /* Remove gcc warning */ TABLE_SHARE *s; handler *file; TABLE *next, *prev ...

  4. UVa 10969 (圆与圆之间的覆盖问题) Sweet Dream

    题意: 有n个按先后顺序放置的不同大小不同位置的圆,求所有可见圆弧的长度. 分析: 这道题应该是大白书上例题 LA 2572 (求可见圆盘的数量) Kanazawa 的加强版,整体框架都差不多. 对于 ...

  5. 通过AJAX与ASP.NET结合实现的仿GridView增删改查功能

    jQurey代码部分: 1.    <script type="text/javascript"> 2.            var flag = 0; 3. 4.  ...

  6. wdcp系统升级mysql5.7.11

    1.下载解压 下载地址为:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz ...

  7. [Sciter系列] MFC下的Sciter–4.HTML与图片资源内置

    [Sciter系列] MFC下的Sciter–4.HTML与图片资源内置,防止代码泄露. 本系列文章的目的就是一步步构建出一个功能可用,接口基本完善的基于MFC框架的SciterFrame程序,以此作 ...

  8. Darwin Streaming Server 安裝操作備忘

    Darwin Streaming Server 安裝操作 Darwin Streaming Server是蘋果公司推出的開放源碼.跨平台多媒體串流伺服器, 提供音樂 (mp3) 與影音 (3gp.mp ...

  9. TS数据结构分析

    1.TS包得数据结构 2. // Transport packet headertypedef struct TS_packet_header{    unsigned sync_byte       ...

  10. SQLlite(WebSQL)如何排序并分页查询(SQLlite语法)

    SELECT * FROM Table ORDER BY ID DESC Limit 10,9 limit语义:跳过10行,取9行 参考: SQLite的limit用法   如果我要去11-20的Ac ...