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> # ...
随机推荐
- [51NOD]BSG白山极客挑战赛
比赛链接:http://www.51nod.com/contest/problemList.html#!contestId=21 /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ min ...
- yeoman运行grunt serve 提示错误
今天在使用 yeoman 的时候,当我运行 grunt serve 命令的时候,出现如下提示: 1.Error: Cannot find module 'load-grunt-tasks' $ gru ...
- char型变量中能存贮一个中文汉字
char型变量是用来存储Unicode编码的字符的,unicode编码字符集中包含了汉字,所以,char型变量中当然可以存储汉字啦.不过,如果某个特殊的汉字没有被包含在unicode编码字符集中,那么 ...
- 玩转EasyUi弹出框
这两天在搞EasyUi的弹出框,弹出框之前也搞过很多个版本,总是觉得不那么完美,刚好最近有时间,就往多处想了想,功能基本上达到我的预期,并且在开发过程中遇到很多小技巧,特撰文如下. 走起:在EasyU ...
- Android ArrayAdapter 详解
本文主要讲解ArrayAdapter的创建方法,我把ArrayAdapter分为三种:简单的.样式丰富的但内容简单的.内容丰富的. 默认的,ArrayAdapter期望接受的样式文件里只含有一个tex ...
- <十一>面向对象分析之UML核心元素之组件
组件
- 使用rsync同步Linux数据到Windows
windows: win7,cwrsyncserver 4.1.0 linux:ubuntu 14.04,rsync 3.1.0 networks:使用360wifi [Windows端] 是否使用管 ...
- VmWare下安装Linux Centos6.0详细过程
http://www.linuxidc.com/Linux/2012-12/76583.htm和http://mirrors.163.com/centos/6.5/isos/i386/这是有关VmWa ...
- 解决虚拟机ssh连接出错connection refused
在安装操作系统之后,使用ssh连接,发现直接报错connection refused. 检查虚拟机的连接方式,在使用host only的方式的时候,必须接入网线,不然的网卡是不活动的,从而不能使用ss ...
- web服务器分析与设计(一)
自己写一个简单的服务器. 面向对象分析与设计第一步:获取需求(基于用例) 功能:1,支持html静态网页,2,支持常用HTTP请求,且容易扩展支持不现请求 3,可以发布站点 补充:至于对动态网页等高级 ...